• jQuery练习6全选反选和全反选


     1 <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
     2 <html>
     3   <head>
     4     <meta http-equiv="content-type" content="text/html; charset=UTF-8">
     5     <script type="text/javascript" src="../js/jquery-1.9.1.js"></script>
     6   </head>
     7   <body>
     8     <table border="1" align="center">
     9         <tr>
    10             <th>状态</th>
    11             <th>用户名</th>
    12         </tr>
    13         <tr>
    14             <td><input type="checkbox"/></td>
    15             <td></td>
    16         </tr>
    17         <tr>
    18             <td><input type="checkbox"/></td>
    19             <td></td>
    20         </tr>        
    21         <tr>
    22             <td><input type="checkbox"/></td>
    23             <td></td>
    24         </tr>    
    25         <tr>
    26             <td><input type="checkbox"/></td>
    27             <td></td>
    28         </tr>
    29         <tr>
    30             <td><input type="checkbox"/></td>
    31             <td></td>
    32         </tr>    
    33         <tr>
    34             <td><input type="button" value="全选中"/></td>
    35             <td><input type="button" value="全取消"/></td>
    36             <td><input type="button" value="全反选"/></td>
    37         </tr>        
    38     </table>
    39     <script type="text/javascript">
    40         
    41             //全取消失效
    42               $(":button:eq(1)").attr("disabled","disabled");
    43         
    44             //1、全选中
    45             var $button1 =  $("input[value='全选中']").first();
    46             $button1.click(function(){
    47                 
    48                 $("input:checkbox").attr("checked","checked");
    49                 //全选中按钮失效
    50                 $(this).attr("disabled","disabled");
    51                 //全取消生效
    52                  $button2.removeAttr("disabled");
    53             });
    54             
    55             //2、全取消
    56             var $button2 =  $("input[value='全取消']");
    57             $button2.click(function(){
    58                 //alert("全取消");
    59                 $("input:checkbox").removeAttr("checked");
    60                 
    61                 //全选中按钮生效
    62                 $button1.removeAttr("disabled");
    63                 //全取消失效
    64                 $(this).attr("disabled","disabled");
    65             });
    66             
    67             //3、全反选
    68             var $button3 =  $("input:button").last();
    69             $button3.click(function(){
    70                 //alert("全反选");
    71                 $(":checkbox:checked").attr("disabled","disabled");
    72                 $(":checkbox:not(:checked)").attr("checked","checked");
    73                 $(":checkbox:disabled").removeAttr("disabled").removeAttr("checked");
    74             });
    75     </script>
    76   </body>
    77 </html>

    注意:在ie6下可以正常运行。但到了ie10,firefox高版本后,只能选一次,后面就不能选了。

  • 相关阅读:
    《C#从现象到本质》读书笔记(八)第10章反射
    《C#从现象到本质》读书笔记(七)第9章 泛型
    《C#从现象到本质》读书笔记(六)第8章委托和事件
    《C#从现象到本质》读书笔记(五)第5章字符串第6章垃圾回收第7章异常与异常处理
    求1+2+……+n的和
    回溯法的应用举例
    回溯法
    翻转单词顺序列
    左旋转字符串
    和为S的两个数字
  • 原文地址:https://www.cnblogs.com/hacket/p/3071770.html
Copyright © 2020-2023  润新知