为什么只有第一次执行的时候有效果还有就是把每个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
$("#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
这个写法就错了啊
这里this,跟标签里的那个this不一样了还有你这样点击了一次全选,那他就已经全选了,你再点也没用啊
$("#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>
我知道this不是jquery对象 但是用了this 确实实现了功能
能帮忙实践下么 。。貌似也不行
求帮助该怎么用jquery 实现
$("#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试试