javascript jquery统一选择和取消选择所有复选框
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/14729286/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
jquery uniform select and deselect all checkbox
提问by Nilesh patel
I have problem with select all / deselect checkbox
我在全选/取消选择复选框时遇到问题
Code Here
代码在这里
<input type="checkbox" value="" onclick="checkedAll();" name="checkall" id="checkall"/>
function checkedAll() {
$('.all span').click(function () {
if(document.getElementById("checkall").checked == true)
{
$('#uniform-undefined span').addClass('checked');
}
else
{
$('#uniform-undefined span').removeClass('checked');
}
});
$.uniform.update();
}
When I select checkbox(for all check box true) jQuery add span tag with class="checked"
当我选择复选框(所有复选框为真)时,jQuery 添加 span 标签 class="checked"
spanTag.addClass(options.checkedClass);
And no one check box are active.
并且没有一个复选框处于活动状态。
<li><label><div id="uniform-undefined" class="checker">">
<span class="checked"><input type="checkbox" value="F2" style="opacity: 0;"></span>
</div><b>1 </b>
</label></li>
<li><label><div id="uniform-undefined" class="checker">
<span class="checked"><input type="checkbox" value="F2" style="opacity: 0;"></span>
</div><b>2 </b>
</label></li>
<li><label><div id="uniform-undefined" class="checker">
<span class="checked"><input type="checkbox" value="F3" style="opacity: 0;"></span>
</div><b>3 </b>
</label></li>
采纳答案by Nishant Jani
回答by MG_Bautista
回答by AndRaGhu
$('document').ready(function(){
$('#all').click(function(){
if($(this).is(':checked')){
$('.group').attr("checked",true);
}
else{
$('.group').attr("checked",false);
}
})
});
this is code is correctly working for the first time only. For the second time if i click the check all check box it is not working. It only got checked.
这是代码仅第一次正确工作。第二次,如果我单击“全选”复选框,则它不起作用。它只是被检查了。
回答by Robert Benyi
Simplest solution call uniform.update:
最简单的解决方案调用uniform.update:
$(".all span").each(function () {
$(this).prop("checked", document.getElementById("checkall").checked );
});
$.uniform.update();
回答by Ajay Kumar
<script>
$('document').ready(function(){
$('#selectAll').click(function(){
if($(this).is(':checked')){
$('#uniform-undefined span').attr("class","checked");
}
else{
$('#uniform-undefined span').attr("class","");
}
})
});
</script>