jquery checkbox 全选和反选

发布时间:2020-07-08 01:04:29 作者:fqogiytbn
来源:网络 阅读:484

两种方法,第一种用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>

推荐阅读:
  1. jQuery操作checkbox选择代码
  2. jquery全选/取消全选(反选)/单选操作

免责声明:本站发布的内容(图片、视频和文字)以原创、转载和分享为主,文章观点不代表本网站立场,如果涉及侵权请联系站长邮箱:is@yisu.com进行举报,并提供相关证据,一经查实,将立刻删除涉嫌侵权内容。

jquery checkbox 全选和反 ue he

上一篇:application master 持续org.apache.hadoop.ipc.Client: Retrying connect to server

下一篇:EXCHANGE DAG环境如何排除ISCSI使用的网络适配器

相关阅读

您好,登录后才能下订单哦!

密码登录
登录注册
其他方式登录
点击 登录注册 即表示同意《亿速云用户服务条款》