在這個主題上有很多問題,但沒有人爲我的問題工作,因爲我不知道如何在我的代碼中應用它們 - 我是jQuery的新手。使用jquery檢查/取消選中所有複選框1.10.2
這是我的HTML頁面:
<div id="one">
<div id="positionable2">
<div id="xyz2">
<table id="tab1">
<tr><td class="header"><input type=checkbox id=cbselectall /></td></tr>
<tr><td ><input type=checkbox name=case /></td></tr>
<tr><td ><input type=checkbox name=case /></td></tr>
<tr><td ><input type=checkbox name=case /></td></tr>
</table>
</div>
</div>
</div>
現在我的jQuery看起來像下面的東西:
$(function() {
$("#one #positionable2 #xyz2 #tab1 #cbselectall").click(function() {
if ($("#one #positionable2 #xyz2 #tab1 #cbselectall").is(':checked')) {
$("#one #positionable2 #xyz2 #tab1 input[type=checkbox]").each(function() {
//$(this).attr("checked", true);
$(this).prop("checked", true);
});
} else {
$("#one #positionable2 #xyz2 #tab1 input[type=checkbox]").each(function() {
//$(this).attr("checked", false);
$(this).prop("checked", false);
});
}
});
});
請注意,我有其他列在表中,使用複選框列是第一柱。在單擊表格標題中的複選框後,應該選擇數據行中的其他列,反之亦然。不知何故,這是行不通的。
由於我是jQuery的新手,不知何故我無法使它工作。請幫忙。
jsfiddle會有所幫助。 – turnt
什麼問題,你的代碼工作正常。這裏是小提琴:http://jsfiddle.net/RCZZ4/ –
在我的頁面與整個頁面內容,它不工作。當我點擊標題複選框時,其他複選框沒有被選中。 –