全选全不选

 <td><input type="checkbox" name="check" value="{$vo.id}">{$vo.id}</td>


<input type="button" class="yes" value="全選">
<input type="button" class="no" value="全不選">
<input type="button" class="yn" value="反選">

//全選
$(document).on("click",".yes",function () {
var check = document.getElementsByName("check");
for (i=0;i<check.length;i++){
if (check[i].checked==false){
check[i].checked = true;
}
}
})
//全不選
$(document).on("click",".no",function () {
var check = document.getElementsByName("check");
for (i=0;i<check.length;i++){
if (check[i].checked==true){
check[i].checked = false;
}
}
})
//反選
$(document).on("click",".yn",function () {
var check = document.getElementsByName("check");
for (i=0;i<check.length;i++){
if (check[i].checked==true){
check[i].checked = false;
}else {
check[i].checked = true;
}
}
})

上一篇:c – 按名称获取属性


下一篇:如何使用getElementsByName方法在javascript中提交表单?