jQuery Checkall 复选框
我无法让此复选框检查未隐藏的复选框
基本上我需要它不检查表中隐藏的任何复选框
ui-tableFilter-hidden
$("input:checkbox.checkall").live('click', function(event){
var checkedStatus = this.checked;
if(!$('table tbody tr').hasClass('ui-tableFilter-hidden'))
{
$("td.small input:checkbox").each(function() {
this.checked = checkedStatus;
});
}
});
快速修复是将上面的代码替换为这个代码
$("input:checkbox.checkall").live('click', function(event){
var checkedStatus = this.checked;
$("td.small input[type=checkbox]:visible").each(function() {
this.checked = checkedStatus;
});
});
I cant get this checkbox to check the checkboxs which are not hidden
Basiclly I need it to not check any check box in the table which is hidden from view
ui-tableFilter-hidden
$("input:checkbox.checkall").live('click', function(event){
var checkedStatus = this.checked;
if(!$('table tbody tr').hasClass('ui-tableFilter-hidden'))
{
$("td.small input:checkbox").each(function() {
this.checked = checkedStatus;
});
}
});
Quick fix was to replace the above code with this one
$("input:checkbox.checkall").live('click', function(event){
var checkedStatus = this.checked;
$("td.small input[type=checkbox]:visible").each(function() {
this.checked = checkedStatus;
});
});
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您的 IF 检查和 EACH 循环在上面的代码中是无关的。 IF 将在某个时刻评估为 true,然后 EACH 循环将迭代与选择器匹配的所有复选框,无论您在 IF 中检查了什么。
尝试这样的事情来代替......
Your IF check and the EACH loop are unrelated in the code above. The IF will evaluate to true at some point and then the EACH loop will iterate through all checkboxes matching the selector, regardless of what you checked in the IF.
Try something like this instead...
理想情况下,您应该使用更改事件,因为不仅仅可以通过单击来更改输入。您还可以查找带有
ui-tableFilter-hidden
的所有行,然后选中相应的复选框。我还使用prop
来标识该框的选中状态,从 jQuery 1.6 开始可用,尽管this.checked
也应该可以工作。Ideally, you should be using the change event, since inputs can be altered with more than just clicks. You can also just find all rows with the
ui-tableFilter-hidden
, then check the appropriate checkboxes. I also useprop
to identify the checked state of the box, available as of jQuery 1.6, althoughthis.checked
should work as well.