码迷,mamicode.com
首页 > 其他好文 > 详细

全选,反选,对话框

时间:2016-07-11 01:07:23      阅读:116      评论:0      收藏:0      [点我收藏+]

标签:

全选,反选列子

技术分享

 

技术分享

技术分享

技术分享
<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
</head>
<body>
     <div>
            <input type="button" value = "全选" ondblclick="CheckAll()">
            <input type="button" value="取消" ondbclick="CancleAll()">
            <input type="button" value="反选" ondblclick="ReverseAll()">
     </div>
     <table>
             <theard>
                       <tr>
                              <th>序号</th>
                              <th>用户名</th>
                              <th>年龄</th>
                       </tr>
             
             </theard>
             <tbody id="tb">
                       <tr>

                           <td><input class="c1" type="checkbox"></td>
                            <td>Wyc</td>
                            <td>17</td>
                       </tr>
                       <tr>

                           <td><input class="c1" type="checkbox"></td>
                            <td>Wyc</td>
                            <td>18</td>
                       </tr>
                       <tr>

                           <td><input class="c1" type="checkbox"></td>
                            <td>Wyc</td>
                            <td>19</td>
                       </tr>
                   
             </tbody>
     </table>
     <script>

           function CeckAll(){
                   var tb = document.getElementById("td");
                   var checks = tb.getElementsByClassName("c1");
                   for(var i=0;i<checks.length;i++){
                            var current_check = checks[i];
                            current_check.checked =true;
                  }
           }
           function CancleAll(){
                    var tb = document.getElementById("tb");
                    var checks = tb.getElementsByClassName("c1");
                     for(var i=0;i<checks.length;i++){
                           var current_check = checks[i];
                           current_check.checked = false;
                     }
            }
            function ReverseAll(){
                    var tb = document.getElementById("tb");
                    var checks = tb.getElementsByClassName("c1");
                    for(var i=0;i<checks.length;i++){
                          var current_check = checks[i];
                          if(current_check.checked){
                              current_check.check = false;
                          }else{
                                     current_check.checked = true;
                          }
                    }
           }

     </script>
</body>
</html>
列子

 

全选,反选,对话框

标签:

原文地址:http://www.cnblogs.com/wuyongcong/p/5659008.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!