您好,登录后才能下订单哦!
两种方法,第一种用jquery的toggle,但这种方法有瑕疵,其它的倒是全选了,可它自己本是却不能选择...只能用第二种方法bind一个click事件,然后判断了
<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>
免责声明:本站发布的内容(图片、视频和文字)以原创、转载和分享为主,文章观点不代表本网站立场,如果涉及侵权请联系站长邮箱:is@yisu.com进行举报,并提供相关证据,一经查实,将立刻删除涉嫌侵权内容。