首页 > 其他 > 详细

Jqurey 全选和全不选

时间:2015-06-11 10:52:05      阅读:286      评论:0      收藏:0      [点我收藏+]
<script src="http://code.jquery.com/jquery-1.4.4.min.js" type="text/javascript"></script>    <script type="text/javascript">
        $(function() {
           $("#checkAll").click(function() {
                $(input[name="subBox"]).attr("checked",this.checked); 
            });
            var $subBox = $("input[name=‘subBox‘]");
            $subBox.click(function(){
                $("#checkAll").attr("checked",$subBox.length == $("input[name=‘subBox‘]:checked").length ? true : false);
            });
        });
    </script>
 
</head>
<body>
    <div>
        <input id="checkAll" type="checkbox" />全选
        <input name="subBox" type="checkbox" />项1
        <input name="subBox" type="checkbox" />项2
        <input name="subBox" type="checkbox" />项3
        <input name="subBox" type="checkbox" />项4
    </div>
</body>

用attr 会有个问题 全选只能使用一次  第一次运行,点select all那个checkbox,可以全选,再点一次,也可以全部取消。但是,之后不管怎样点击,都没有用了……

百度了一下 用prop 替换使用attr 就可以勒

区别  http://www.cnblogs.com/zhwl/p/3520162.html

 

<script src="http://code.jquery.com/jquery-1.4.4.min.js" type="text/javascript"></script>    <script type="text/javascript">
        $(function() {
           $("#checkAll").click(function() {
                $(input[name="subBox"]).prop("checked",this.checked); 
            });
            var $subBox = $("input[name=‘subBox‘]");
            $subBox.click(function(){
                $("#checkAll").prop("checked",$subBox.length == $("input[name=‘subBox‘]:checked").length ? true : false);
            });
        });
    </script>
 
</head>
<body>
    <div>
        <input id="checkAll" type="checkbox" />全选
        <input name="subBox" type="checkbox" />项1
        <input name="subBox" type="checkbox" />项2
        <input name="subBox" type="checkbox" />项3
        <input name="subBox" type="checkbox" />项4
    </div>
</body>

 

Jqurey 全选和全不选

原文:http://www.cnblogs.com/acgk/p/4568312.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!