日期:2014-05-16  浏览次数:20482 次

jquery、中 checkbox 全选 全部选 反选的问题
为什么只有第一次执行的时候有效果。。。还有就是把每个click事件里的最后句换成注视的就可以了。。能解释下吗

   $(document).ready(function () {
            $("#all").click(function () {
                $("input[name=checkbox]").each(function () {
                    $(this).attr("checked",true);
//                    this.checked = true;
                });
            });
            $("#none").click(function () {

                $("input[name=checkbox]").each(function () {
                    $(this).attr("checked",false);
//                    this.checked = false;
                });
            });
            $("#aa").click(function () {
                $("input[name=checkbox]").each(function () {
                  $(this).attr("checked",! $(this).attr("checked"));
                    this.checked = !this.checked;
                });

            });


        });
    
    </script>
</head>
<body>

<div id="box">
<input  type="checkbox" name="checkbox"   />中国<br />
<input type="checkbox" name="checkbox"   />巴西<br />
<input type="checkbox" name="checkbox"   />美国<br />
<input type="checkbox" name="checkbox"   />英国<br />
</div>
<br />
<input type="button" id="all" value="全选" />
<input type="button" id="none" value="全不选" />
<input type="button" id="aa"  value="反选" />
</body>
jQuery CheckBox