jsp中checkbox复选框的个数是依据从数据库中取出值的条数决定的,是Iterator循环遍历出来的。
<td class="rd8"> <input type="checkbox" name="selectFlag" id="selectFlag" value="<%=user.getUser_id()%>"> </td>
第一种方法:
//全选
$("#checkAll").click(function() {
if (this.checked) {
$("input[name='selectFlag']:checkbox").each(function() { //遍历所有的name为selectFlag的 checkbox
$(this).attr("checked", true);
})
}
})
//取消全选
$("#delCheckAll").click(function() {
if (this.checked) {
$("input[name='selectFlag']:checkbox").each(function() { //遍历所有的name为selectFlag的 checkbox
$(this).attr("checked", false);
})
}
})
更简单直接的一种:
$("#checkAll").click(function() {
if (this.checked) {
$("input[name='selectFlag']:checkbox").each(function() { //遍历所有的name为selectFlag的 checkbox
$(this).attr("checked", true);
})
} else { //反之 取消全选
$("input[name='selectFlag']:checkbox").each(function() { //遍历所有的name为selectFlag的 checkbox
$(this).attr("checked", false);
//alert("f");
})
}
})
原创文章,作者:ItWorker,如若转载,请注明出处:https://blog.ytso.com/tech/pnotes/14458.html