如何使用复选框数组的 id 检查复选框数组中的复选框是否被选中?
我正在使用以下代码,但它总是返回选中复选框的计数,而不管 id。
function isCheckedById(id) {
alert(id);
var checked = $("input[@id=" + id + "]:checked").length;
alert(checked);
if (checked == 0) {
return false;
} else {
return true;
}
}
最佳答案
$('#' + id).is(":checked")
如果复选框被选中,就会得到。
对于具有相同名称的复选框数组,您可以通过以下方式获取选中的列表:
var $boxes = $('input[name=thename]:checked');
然后遍历它们,看看你能做什么检查:
$boxes.each(function(){
// Do stuff here with this
});
要查找检查了多少,您可以执行以下操作:
$boxes.length;
关于javascript - 检查是否使用 jQuery 检查了复选框,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2204250/