我有兩個表:使用jQuery突顯TR的還是TD的
<table class="highlight_row" id="table1">
<tr id="first_row">
<td><input type="checkbox" id="first">first thing</td>
<td><input type="checkbox" id="second">second thing</td>
<td><input type="checkbox" id="third">third thing</td>
</tr>
</table>
<table class="highlight_td" id="table2">
<tr id="second_row">
<td><input type="checkbox" id="fourth">fourth thing</td>
<td><input type="checkbox" id="fifth">fifth thing</td>
<td><input type="checkbox" id="sixth">sixth thing</td>
</tr>
</table>
,我試圖者區分他們 - 當我在第一個表檢查所有箱子,我想這全行突出,當我在第二張表格中選中一個框時,我只需要突出顯示td。我可以得到突出顯示的行(使用addClass()爲'selected'顏色),但是當我指定表類時,我仍然得到第二個表的整行,當我只想要td(由於我增加了更多的表格,因此從長遠來看,我可以通過班級而不是id來識別)。
jQuery代碼:
$(".highlight_row").click(function(){
$(":checkbox").change(function() {
$(this).closest("tr").toggleClass("selected", this.checked)
})
});
安置自己的jQuery的親本細胞類 - I F鰻魚就像你可能會選擇所有'td'元素作爲你的第一個例子。 – Purag
你不能在一個頁面中重複ID ...他們根據定義是唯一的。郵編不工作,所以人們可以幫助你找出原因。您通過更多的方式學習,我們不必重新發明 – charlietfl
我們可以看到您的jQuery事件調用嗎?正如上面的用戶所說,可能會抓住錯誤的元素 – code