码迷,mamicode.com
首页 > Web开发 > 详细

checkbox全选jquery

时间:2014-09-07 18:24:55      阅读:230      评论:0      收藏:0      [点我收藏+]

标签:style   blog   http   color   io   java   ar   2014   div   

bubuko.com,布布扣

<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
    <title>selectAll</title>
    <style type="text/css">
       table {
            border: 1px solid red;
            border-collapse:collapse;
            width:300px;
            margin :auto;
            text-align:center;
               
                

        }
    </style>
    <script src="js/jquery-1.7.1.js"></script>
  
    <script type="text/javascript">
        $(function () {
            $(".all").click(function () {
                if ($(".all").attr("checked")) {//全选
                   
                    $(".cc").attr("checked", true);
                }
                else {//取消全选
                    $(".cc").removeAttr("checked");
                }
               
            })

            $(".cc").click(function () {
                SelectAll();
            })


        })


        function SelectAll() {
            
            if (!$(".cc").attr("checked")) {//未选中
                $(".all").attr("checked",false)
            }
            else {//全部选中
                $(".all").attr("checked", true)
            }


        }
    </script>
</head>
<body>
    <table id="tb" border="1">
        <tr>
            <td>序列</td>
        </tr>
         <tr>
            <td>
                <input type="checkbox" class="cc"/></td>    </tr>
              <tr>
            <td><input type="checkbox" class="cc"/></td>
    
        </tr>
         <tr>
            <td><input type="checkbox" class="cc"/></td>
    
        </tr>
         <tr>
            <td><input type="checkbox" class="cc"/></td>
    
        </tr>
         <tr>
            <td><input type="checkbox" class="all"  />all</td>
    
        </tr>
    </table>
</body>
</html>

 

checkbox全选jquery

标签:style   blog   http   color   io   java   ar   2014   div   

原文地址:http://www.cnblogs.com/junhuang/p/3960583.html

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