JQuery脚本没有正确检查复选框 [英] JQuery Script not checking check-boxes correctly

查看:65
本文介绍了JQuery脚本没有正确检查复选框的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有两个功能,我已经做了这个检查,并取消选中具有特定类的所有复选框。我第一次运行它们按预期方式执行的函数,但在尝试再次运行该函数后,复选框不检查,但html代码发生了更改。



JQuery。 ...

pre $ 函数checkall(){
$('。column')。attr('checked','检查');
$('#ALL')。attr('onclick','uncheckall()')
document.getElementById('ALL')。value =UnCheck All;
}

运行后,我得到< input type = checkboxvalue =SEQNclass =columnonchange =updatearray()checked =checked>

 函数uncheckall(){
$('。column')。removeAttr('checked');
$('#ALL')。attr('onclick','checkall()')
document.getElementById('ALL')。value =全部检查;
}

运行后,我得到< input type = checkboxvalue =SEQNclass =columnonchange =updatearray()> p为什么复选框只改变一次?

解决方案

尝试使用prop()而不是attr()如果问题仍然存在迭代个别复选框


I have two functions that I have made that check and uncheck all check boxes with a specific class. the first time I run the functions they do as expected but after I try to run the function again the check boxes do not check, but the html code changes.

JQuery...

function checkall() {
   $('.column').attr('checked','checked');
   $('#ALL').attr('onclick', 'uncheckall()')
   document.getElementById('ALL').value = "UnCheck All";
}

after running this I get <input type="checkbox" value="SEQN" class="column" onchange="updatearray()" checked="checked">

function uncheckall() {
   $('.column').removeAttr('checked');
   $('#ALL').attr('onclick', 'checkall()')
   document.getElementById('ALL').value = "Check All";
}

after running this I get <input type="checkbox" value="SEQN" class="column" onchange="updatearray()">

Why do the check-boxes only change once?

解决方案

Try prop() instead attr().If issue still persist iterate individual checkbox

这篇关于JQuery脚本没有正确检查复选框的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆