为什么只有第一次执行的时候有效果还有就是把每个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>jQueryCheckBox

解决方案 »

  1.   

    //                    this.checked = true;
    这个写法就错了啊
    这里this,跟标签里的那个this不一样了还有你这样点击了一次全选,那他就已经全选了,你再点也没用啊
      

  2.   

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

  3.   

    我的意思是  你第一次按了全选之后  然后在按全部选(或者人为去掉几个)   在按全选没效果了
      我知道this不是jquery对象 但是用了this  确实实现了功能
      

  4.   

    能解释解释么。。困惑我好久了在js中控制checked属性给他赋值是"checked",而不是true,selected也是selected="selected";
      

  5.   

    能解释解释么。。困惑我好久了在js中控制checked属性给他赋值是"checked",而不是true,selected也是selected="selected";
    能帮忙实践下么 。。貌似也不行
      

  6.   


    求帮助该怎么用jquery 实现
      

  7.   

    $(document).ready(function () {
                $("#all").click(function () {
                    $("input[name=checkbox]").each(function () {
                        $(this).prop("checked",true);
    //                    this.checked = "checked";
                    });
                });
                $("#none").click(function () {
     
                    $("input[name=checkbox]").each(function () {
                        $(this).prop("checked",false);
    //                    this.checked = "";
                    });
                });
                $("#aa").click(function () {
                    $("input[name=checkbox]").each(function () {
                      $(this).prop("checked",! $(this).attr("checked"));
                        this.checked = !this.checked;
                    });
     
                });
     
     
            });
         
        </script>换成prop试试