http://briancray.com/tests/checkboxes/index.html http://briancray.com/tests/checkboxes/index.html
select all 的实现方式很简单,但并不完美。全选和取消全选工作正常,但在全选状态下,如果取消选中其中一项,全选也会被选中。如何纠正这个问题?
then
“全部检查”仍然被选中。如何纠正这个问题?
Warning, shameless self-promotion ahead.
我已经为 jQuery 编写了一个插件,它就是做这种事情的。看一看:http://mjball.github.com/jQuery-CheckAll http://mjball.github.com/jQuery-CheckAll
要将其与链接页面上的标记一起使用:
<form action="#" method="post" id="myform">
<fieldset>
<div class="radio"><input type="checkbox" name="checkall" id="checkall"> <label for="checkall">Check all</label></div>
<div class="radio"><input type="checkbox" name="checkbox1" id="checkbox1"> <label for="checkbox1">Checkbox</label></div>
<div class="radio"><input type="checkbox" name="checkbox2" id="checkbox2"> <label for="checkbox2">Checkbox</label></div>
<div class="radio"><input type="checkbox" name="checkbox3" id="checkbox3"> <label for="checkbox3">Checkbox</label></div>
<div class="radio"><input type="checkbox" name="checkbox4" id="checkbox4"> <label for="checkbox4">Checkbox</label></div>
<div class="radio"><input type="checkbox" name="checkbox5" id="checkbox5"> <label for="checkbox5">Checkbox</label></div>
<div class="radio"><input type="checkbox" name="checkbox6" id="checkbox6"> <label for="checkbox6">Checkbox</label></div>
<div class="radio"><input type="checkbox" name="checkbox7" id="checkbox7"> <label for="checkbox7">Checkbox</label></div>
<div class="radio"><input type="checkbox" name="checkbox8" id="checkbox8"> <label for="checkbox8">Checkbox</label></div>
<div class="radio"><input type="checkbox" name="checkbox9" id="checkbox9"> <label for="checkbox9">Checkbox</label></div>
<div class="radio"><input type="checkbox" name="checkbox10" id="checkbox10"> <label for="checkbox10">Checkbox</label></div>
</fieldset>
</form>
这就足够了:
$('#checkall').checkAll('#myform input:checkbox:not(#checkall)');
Demo: http://jsfiddle.net/mattball/npeTz/ http://jsfiddle.net/mattball/npeTz/
CheckAll works correctly with jQuery 1.4.4 and 1.5.2. I have not had time to update it for jQuery 1.6. sorry.
更新了 jQuery 1.6 兼容性:http://jsfiddle.net/mattball/CVQsp/ http://jsfiddle.net/mattball/CVQsp/
即使您不小心选择了主服务器和从服务器,它仍然有效:http://jsfiddle.net/mattball/BwFvc/ http://jsfiddle.net/mattball/BwFvc/
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)