两种方法,第一种用jquery的toggle,但这种方法有瑕疵,其它的倒是全选了,可它自己本是却不能选择...只能用第二种方法bind一个click事件,然后判断了
10年积累的成都网站设计、网站制作经验,可以快速应对客户对网站的新想法和需求。提供各种问题对应的解决方案。让选择我们的客户得到更好、更有力的网络服务。我虽然不认识你,你也不认识我。但先网站制作后付款的网站建设流程,更有宽城免费网站建设让你可以放心的选择与我们合作。
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.8.2/jquery.min.js"></script>
<script>
$(function(){
//方法一
/*
$("#checkAll").toggle(
function(){
$.each($("input[type='checkbox']"), function(){$(this).attr("checked",true);},
function(){$.each($("input[type='checkbox']"), function(){$(this).attr("checked",false);}
);
*/
//方法二
$("#checkAll").bind("click",function(){
if($("#checkAll").attr("checked")){
$("#margin_total").hide();
$.each($("input[type='checkbox']"), function(){$(this).attr("checked",true);});
}else{
$("#margin_total").show();
$.each($("input[type='checkbox']"), function(){$(this).attr("checked",false);});
}
})
})
</script>
<html>
<body>
<table width="100%" border="0" cellspacing="0" cellpadding="0">
<tr>
<th><input id="checkAll" type="checkbox" /></th>
<th> - </th>
<th> - </th>
</tr>
<tr>
<td><input type="checkbox" /></td>
<td> - </td>
<td> - </td>
</tr>
<tr>
<td><input type="checkbox" /></td>
<td> - </td>
<td> - </td>
</tr>
<tr>
<td><input type="checkbox" /></td>
<td> - </td>
<td> - </td>
</tr>
</table>
</body>
</html>
当前标题:jquerycheckbox全选和反选
浏览地址:https://www.cdcxhl.com/article10/peosgo.html
成都网站建设公司_创新互联,为您提供、面包屑导航、品牌网站制作、做网站、服务器托管、品牌网站建设
声明:本网站发布的内容(图片、视频和文字)以用户投稿、用户转载内容为主,如果涉及侵权请尽快告知,我们将会在第一时间删除。文章观点不代表本网站立场,如需处理请联系客服。电话:028-86922220;邮箱:631063699@qq.com。内容未经允许不得转载,或转载时需注明来源: 创新互联