选中复选框(如果可见) [英] check the checkbox if visible
本文介绍了选中复选框(如果可见)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有一个复选框列表,并且我有一个select_all复选框.请检查代码中的注释.
I have a list of checkboxes and i have a select_all checkbox. Please check the comment in the code.
$('#select_all').change(function() {
var checkboxes = $("input[name^='select']");
if($('#select_all').is(':checked')) {
//here i want to check where this checkbox (checkbox from the list not select_all checkbox) is visible or not.
// if visible then check the checkbox
checkboxes.attr('checked', 'checked');
} else {
checkboxes.removeAttr('checked');
}
});
有没有这样的想法来检查可见性:-
Is there any think like this to check the visibility:--
$("input[name^='select'][checked]").each(
function() {
// Insert code here
}
);
推荐答案
使用:visible选择器.
$('#select_all').change(function() {
var checkboxes = $("input[name^='select']");
if (this.checked) {
checkboxes.filter(':visible').attr('checked', true);
} else {
checkboxes.attr('checked', false);
}
});
请注意我如何使用正确的方法来设置checked
属性;该值应该是布尔值,而不是字符串.
Note how I've used the correct method of setting the checked
attribute; the value should be a boolean, not a string.
这篇关于选中复选框(如果可见)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文