私は次のことで頭がおかしくなっています:
動的に挿入された一連の要素にクリック ハンドラーをアタッチしました。基本的なレベルでは、クリックしたものに 1 ピクセルの赤一色の境界線を追加しようとしています。ただし、動的要素をクリックすると、2 つの異なる一意の div 内の要素の同じ位置が境界線になります。ページに静的要素があった場合、その要素は一意になります。スクリーンキャストで例を示しましょう。
スクリーンキャスト: http://screencast.com/t/HguCjodWzM4A
setDifficulty = ->
$("[data-difficulty]").click (e) ->
e.preventDefault()
$(this).css("border", "1px solid red")
これは、要素の動的挿入時にコールバックを介してトリガーされます。setDifficulty()
ドロップダウンの問題の HTML:
%a{"data-dropdown" => "log_entry_#{log_entry_random_stamp}_difficulty", :href => "#", :class => "small button split change-difficulty"} <b data-difficulty-value>#{f.object.expected_difficulty}</b> <span></span>
%ul.f-dropdown.poop{"data-dropdown-content" => "", id: "log_entry_#{log_entry_random_stamp}_difficulty"}
%li
%a{:href => "#", :"data-difficulty" => "effortless"} Effortless
%li
%a{:href => "#", :"data-difficulty" => "easy"} Easy
%li
%a{:href => "#", :"data-difficulty" => "moderate"} Moderate
%li
%a{:href => "#", :"data-difficulty" => "hard"} Hard
%li
%a{:href => "#", :"data-difficulty" => "maximum"} Maximum
編集: dom でレンダリングされたコードは次のとおりです。
<table class="todays-logs table log-entries">
<thead>
<tr>
<th class="set">Set</th>
<th>Reps</th>
<th>
Weight
</th>
<th>Rest (mins)</th>
<th>Difficulty</th>
</tr>
</thead>
<tbody>
<tr class="nested-fields log-entry-fields">
<td class="set">1</td>
<td class="reps">
<li class="number input optional numeric stringish" id="exercise_log_entries_attributes_0_reps_input"><input id="exercise_log_entries_attributes_0_reps" name="exercise[log_entries_attributes][0][reps]" placeholder="How many?" step="any" type="number">
</li>
</td>
<td class="weight">
<div class="row collapse">
<div class="large-4 columns">
<span class="prefix">
<a href="#" class="convert-weight" data-dropdown="convert-weight">kg</a>
<span class="icon-caret-down"></span>
<ul class="f-dropdown" data-dropdown-content="" id="convert-weight">
<li><a href="" class="convert convert-to-lb" data-dropdown="convert-weight">lb</a></li>
<li><a href="" class="convert convert-to-kg" data-dropdown="convert-weight">kg</a></li>
</ul>
</span>
</div>
<div class="large-8 columns">
<li class="number input optional numeric stringish" id="exercise_log_entries_attributes_0_weight_input"><input class="weight" data-weight="24" id="exercise_log_entries_attributes_0_weight" name="exercise[log_entries_attributes][0][weight]" placeholder="Pounds" step="any" type="number" value="11">
</li>
</div>
</div>
<input data-measurement="lb" id="exercise_log_entries_attributes_0_measurement" name="exercise[log_entries_attributes][0][measurement]" type="hidden" value="kg">
</td>
<td class="set-duration">
<li class="number input optional numeric stringish" id="exercise_log_entries_attributes_0_rest_after_set_input"><input id="exercise_log_entries_attributes_0_rest_after_set" name="exercise[log_entries_attributes][0][rest_after_set]" placeholder="Rest" step="any" type="number">
</li>
</td>
<td class="difficulty">
<a class="small button split change-difficulty" data-dropdown="log_entry_1367446248252094_difficulty" href="#"><b data-difficulty-value="">easy</b> <span></span></a>
<ul class="f-dropdown poop" data-dropdown-content="" id="log_entry_1367446248252094_difficulty" style="position: absolute; top: 79px; left: -99999px;">
<li>
<a data-difficulty="effortless" href="#">Effortless</a>
</li>
<li>
<a data-difficulty="easy" href="#" style="border: 1px solid red;">Easy</a>
</li>
<li>
<a data-difficulty="moderate" href="#">Moderate</a>
</li>
<li>
<a data-difficulty="hard" href="#" style="border: 1px solid red;">Hard</a>
</li>
<li>
<a data-difficulty="maximum" href="#" style="border: 1px solid red;">Maximum</a>
</li>
</ul>
<input data-difficulty-value="" id="exercise_log_entries_attributes_0_difficulty" name="exercise[log_entries_attributes][0][difficulty]" type="hidden" value="easy">
</td>
<td class="remove">
<input id="exercise_log_entries_attributes_0__destroy" name="exercise[log_entries_attributes][0][_destroy]" type="hidden"><a href="#" class="delete remove_fields existing"><i class="icon-trash"></i></a>
</td>
</tr>
<input id="exercise_log_entries_attributes_0_id" name="exercise[log_entries_attributes][0][id]" type="hidden" value="99"><tr class="nested-fields log-entry-fields">
<td class="set">2</td>
<td class="reps">
<li class="number input optional numeric stringish" id="exercise_log_entries_attributes_1367446253006_reps_input"><input id="exercise_log_entries_attributes_1367446253006_reps" name="exercise[log_entries_attributes][1367446253006][reps]" placeholder="How many?" step="any" type="number">
</li>
</td>
<td class="weight">
<div class="row collapse">
<div class="large-4 columns">
<span class="prefix">
<a href="#" class="convert-weight" data-dropdown="convert-weight">lb</a>
<span class="icon-caret-down"></span>
<ul class="f-dropdown" data-dropdown-content="" id="convert-weight">
<li><a href="" class="convert convert-to-lb" data-dropdown="convert-weight">lb</a></li>
<li><a href="" class="convert convert-to-kg" data-dropdown="convert-weight">kg</a></li>
</ul>
</span>
</div>
<div class="large-8 columns">
<li class="number input optional numeric stringish" id="exercise_log_entries_attributes_1367446253006_weight_input"><input class="weight" data-weight="null" id="exercise_log_entries_attributes_1367446253006_weight" name="exercise[log_entries_attributes][1367446253006][weight]" placeholder="Pounds" step="any" type="number">
</li>
</div>
</div>
<input data-measurement="lb" id="exercise_log_entries_attributes_1367446253006_measurement" name="exercise[log_entries_attributes][1367446253006][measurement]" type="hidden" value="lb">
</td>
<td class="set-duration">
<li class="number input optional numeric stringish" id="exercise_log_entries_attributes_1367446253006_rest_after_set_input"><input id="exercise_log_entries_attributes_1367446253006_rest_after_set" name="exercise[log_entries_attributes][1367446253006][rest_after_set]" placeholder="Rest" step="any" type="number">
</li>
</td>
<td class="difficulty">
<a class="small button split change-difficulty" data-dropdown="log_entry_1367446248258956_difficulty" href="#"><b data-difficulty-value="">Difficulty</b> <span></span></a>
<ul class="f-dropdown poop" data-dropdown-content="" id="log_entry_1367446248258956_difficulty" style="position: absolute; top: 237px; left: -99999px;">
<li>
<a data-difficulty="effortless" href="#" style="border: 1px solid red;">Effortless</a>
</li>
<li>
<a data-difficulty="easy" href="#" style="border: 1px solid red;">Easy</a>
</li>
<li>
<a data-difficulty="moderate" href="#" style="border: 1px solid red;">Moderate</a>
</li>
<li>
<a data-difficulty="hard" href="#" style="border: 1px solid red;">Hard</a>
</li>
<li>
<a data-difficulty="maximum" href="#" style="border: 1px solid red;">Maximum</a>
</li>
</ul>
<input data-difficulty-value="" id="exercise_log_entries_attributes_1367446253006_difficulty" name="exercise[log_entries_attributes][1367446253006][difficulty]" type="hidden">
</td>
<td class="remove">
<input id="exercise_log_entries_attributes_1367446253006__destroy" name="exercise[log_entries_attributes][1367446253006][_destroy]" type="hidden"><a href="#" class="delete remove_fields dynamic"><i class="icon-trash"></i></a>
</td>
</tr><tr class="nested-fields log-entry-fields">
<td class="set">3</td>
<td class="reps">
<li class="number input optional numeric stringish" id="exercise_log_entries_attributes_1367446253899_reps_input"><input id="exercise_log_entries_attributes_1367446253899_reps" name="exercise[log_entries_attributes][1367446253899][reps]" placeholder="How many?" step="any" type="number">
</li>
</td>
<td class="weight">
<div class="row collapse">
<div class="large-4 columns">
<span class="prefix">
<a href="#" class="convert-weight" data-dropdown="convert-weight">lb</a>
<span class="icon-caret-down"></span>
<ul class="f-dropdown" data-dropdown-content="" id="convert-weight">
<li><a href="" class="convert convert-to-lb" data-dropdown="convert-weight">lb</a></li>
<li><a href="" class="convert convert-to-kg" data-dropdown="convert-weight">kg</a></li>
</ul>
</span>
</div>
<div class="large-8 columns">
<li class="number input optional numeric stringish" id="exercise_log_entries_attributes_1367446253899_weight_input"><input class="weight" data-weight="null" id="exercise_log_entries_attributes_1367446253899_weight" name="exercise[log_entries_attributes][1367446253899][weight]" placeholder="Pounds" step="any" type="number">
</li>
</div>
</div>
<input data-measurement="lb" id="exercise_log_entries_attributes_1367446253899_measurement" name="exercise[log_entries_attributes][1367446253899][measurement]" type="hidden" value="lb">
</td>
<td class="set-duration">
<li class="number input optional numeric stringish" id="exercise_log_entries_attributes_1367446253899_rest_after_set_input"><input id="exercise_log_entries_attributes_1367446253899_rest_after_set" name="exercise[log_entries_attributes][1367446253899][rest_after_set]" placeholder="Rest" step="any" type="number">
</li>
</td>
<td class="difficulty">
<a class="small button split change-difficulty" data-dropdown="log_entry_1367446248258956_difficulty" href="#"><b data-difficulty-value="">Difficulty</b> <span></span></a>
<ul class="f-dropdown poop" data-dropdown-content="" id="log_entry_1367446248258956_difficulty">
<li>
<a data-difficulty="effortless" href="#">Effortless</a>
</li>
<li>
<a data-difficulty="easy" href="#">Easy</a>
</li>
<li>
<a data-difficulty="moderate" href="#">Moderate</a>
</li>
<li>
<a data-difficulty="hard" href="#">Hard</a>
</li>
<li>
<a data-difficulty="maximum" href="#">Maximum</a>
</li>
</ul>
<input data-difficulty-value="" id="exercise_log_entries_attributes_1367446253899_difficulty" name="exercise[log_entries_attributes][1367446253899][difficulty]" type="hidden">
</td>
<td class="remove">
<input id="exercise_log_entries_attributes_1367446253899__destroy" name="exercise[log_entries_attributes][1367446253899][_destroy]" type="hidden"><a href="#" class="delete remove_fields dynamic"><i class="icon-trash"></i></a>
</td>
</tr><tr class="normalize">
<td colspan="5">
<div class="links">
<a href="#" class="add-set add_fields" data-association-insertion-template="<tr class='nested-fields log-entry-fields'>
<td class='set'>
0
</td>
<td class='reps'>
<li class="number input optional numeric stringish" id="exercise_log_entries_attributes_new_log_entries_reps_input"><input id="exercise_log_entries_attributes_new_log_entries_reps" name="exercise[log_entries_attributes][new_log_entries][reps]" placeholder="How many?" step="any" type="number" />
</li>
</td>
<td class='weight'>
<div class='row collapse'>
<div class='large-4 columns'>
<span class='prefix'>
<a href="#" class="convert-weight" data-dropdown="convert-weight">lb</a>
<span class='icon-caret-down'></span>
<ul class='f-dropdown' data-dropdown-content='' id='convert-weight'>
<li><a href="" class="convert convert-to-lb" data-dropdown="convert-weight">lb</a></li>
<li><a href="" class="convert convert-to-kg" data-dropdown="convert-weight">kg</a></li>
</ul>
</span>
</div>
<div class='large-8 columns'>
<li class="number input optional numeric stringish" id="exercise_log_entries_attributes_new_log_entries_weight_input"><input class="weight" data-weight="null" id="exercise_log_entries_attributes_new_log_entries_weight" name="exercise[log_entries_attributes][new_log_entries][weight]" placeholder="Pounds" step="any" type="number" />
</li>
</div>
</div>
<input data-measurement="lb" id="exercise_log_entries_attributes_new_log_entries_measurement" name="exercise[log_entries_attributes][new_log_entries][measurement]" type="hidden" value="lb" />
</td>
<td class='set-duration'>
<li class="number input optional numeric stringish" id="exercise_log_entries_attributes_new_log_entries_rest_after_set_input"><input id="exercise_log_entries_attributes_new_log_entries_rest_after_set" name="exercise[log_entries_attributes][new_log_entries][rest_after_set]" placeholder="Rest" step="any" type="number" />
</li>
</td>
<td class='difficulty'>
<a class='small button split change-difficulty' data-dropdown='log_entry_1367446248258956_difficulty' href='#'><b data-difficulty-value>Difficulty</b> <span></span></a>
<ul class='f-dropdown poop' data-dropdown-content='' id='log_entry_1367446248258956_difficulty'>
<li>
<a data-difficulty='effortless' href='#'>Effortless</a>
</li>
<li>
<a data-difficulty='easy' href='#'>Easy</a>
</li>
<li>
<a data-difficulty='moderate' href='#'>Moderate</a>
</li>
<li>
<a data-difficulty='hard' href='#'>Hard</a>
</li>
<li>
<a data-difficulty='maximum' href='#'>Maximum</a>
</li>
</ul>
<input data-difficulty-value="" id="exercise_log_entries_attributes_new_log_entries_difficulty" name="exercise[log_entries_attributes][new_log_entries][difficulty]" type="hidden" />
編集: その他のヒント: から取り出すと、f-dropdown
期待どおりに動作します。どういうわけか、Foundation のドロップダウン メニューの動的な性質により、おかしくなっています。