zoukankan      html  css  js  c++  java
  • JQuery实现全选、反选和取消功能

     1 <!DOCTYPE html>
     2 <html lang="en">
     3 <head>
     4     <meta charset="UTF-8">
     5     <title>JQ实现正、反选</title>
     6 </head>
     7 <body>
     8     <table  border="1px" style=" 200px;margin-bottom: 10px">
     9         <thead>
    10             <tr>
    11                 <th>#</th>
    12                 <th>姓名</th>
    13                 <th>性别</th>
    14             </tr>
    15         </thead>
    16         <tbody>
    17             <tr>
    18                 <td><input type="checkbox"></td>
    19                 <td>Alex</td>
    20                 <td>女</td>
    21             </tr>
    22             <tr>
    23                 <td><input type="checkbox"></td>
    24                 <td>Egon</td>
    25                 <td>女</td>
    26             </tr>
    27             <tr>
    28                 <td><input type="checkbox"></td>
    29                 <td>Qimi</td>
    30                 <td>女</td>
    31             </tr>
    32         </tbody>
    33     </table>
    34     <input type="button"  value="全选" id="i1" class="c1">
    35     <input type="button" value="反选" id="i2" class="c1">
    36     <input type="button" value="取消" id="i3">
    37     <script src="jquery-3.2.1.js"></script>
    38     <script>
    39         // <!-----------------------------------全选------------------------------------>
    40         var $in_1 = $("#i1");
    41         //用第一种循环的方式全部选中,each的循环体不用加索引取值
    42         // $in_1.on("click",function () {
    43         //     var $cheele = $(":checkbox");
    44         //     $cheele.each(function () {
    45         //         //为input标签增加固有属性checked
    46         //         $(this).prop("checked",true);
    47         //     })
    48         // });
    49         //用第二种循环的方式全部选中
    50         // $in_1.click("click",function () {
    51         //     var $cheele = $(":checkbox");
    52         //     $.each($cheele,function () {
    53         //         $(this).prop("checked",true);
    54         //     })
    55         // });
    56         //另一种全选的方法
    57             //要执行的语句不能直接你跟在","之后!!!
    58         $in_1.on("click",function () {
    59             $(":checkbox").prop("checked",true);
    60         });
    61         //-----------------------------------------取消--------------------------------------------------
    62         var $in_2 = $("#i3");
    63         $in_2.on("click",function () {
    64             $(":checkbox").prop("checked",false);
    65         });
    66         //-----------------------------------------反选--------------------------------------------------
    67         var $in_3 = $("#i2");
    68         $in_3.on("click",function () {
    69             $(":checkbox").each(function () {
    70                 $(this).prop("checked",!$(this).prop("checked"));
    71             })
    72         });
    73     </script>
    74 </body>
    75 </html>
  • 相关阅读:
    hibernate框架的搭建与简单实现增删改
    $.ajax();详解
    利用json实现数据传输
    利用ajax实现数据传输
    错误:Value '0000-00-00 00:00:00' can not be represented as java.sql.Timestamp;的解决
    简单使用jstl实现敏感字替换
    实用jstl实现未登录时不能绕过登录界面的效果
    简单实用jstl实现“登录|注册”
    简单实用jstl实现代码编写
    简单使用EL进行标签的替换
  • 原文地址:https://www.cnblogs.com/liuyinzhou/p/8179021.html
Copyright © 2011-2022 走看看