找到jQuery中所有未选中的复选框
问题描述:
我有一个复选框列表:找到jQuery中所有未选中的复选框
<input type="checkbox" name="answer" id="id_1' value="1" />
<input type="checkbox" name="answer" id="id_2' value="2" />
...
<input type="checkbox" name="answer" id="id_n' value="n" />
我可以收集选中的复选框的所有值;我的问题是如何获得未经检查的复选框的所有值?我想:
$("input:unchecked").val();
获得一个未选中的复选框的价值,但我得到:
语法错误,无法识别的表达式:选中。
有谁能够阐明这个问题光?谢谢!
答
$.extend($.expr[':'], {
unchecked: function (obj) {
return ((obj.type == 'checkbox' || obj.type == 'radio') && !$(obj).is(':checked'));
}
});
$("input:unchecked")
答
$("input[type='checkbox']:not(:checked):not('\#chkAll\')").map(function() {
var a = "";
if (this.name != "chkAll") {
a = this.name + "|off";
}
return a;
}).get().join();
这会检索所有选中的复选框,并排除“chkAll”复选框,我用它来检查|取消所有复选框。由于我想知道我传递给数据库的价值,所以我将它们设置为off,因为复选框给我一个值。
//looking for unchecked checkboxes, but don’t include the checkbox all that checks or unchecks all checkboxes
//.map - Pass each element in the current matched set through a function, producing a new jQuery object containing the return values.
//.get - Retrieve the DOM elements matched by the jQuery object.
//.join - (javascript) joins the elements of an array into a string, and returns the string.The elements will be separated by a specified separator. The default separator is comma (,).
+1
你不应该在你的回答中加入与OP完全无关的东西。他没有使用“chkAll”框,所以提及它有什么意义。 – MMM
答
你可以使用这样的:
$(":checkbox:not(:checked)")
答
$(".clscss-row").each(function() {
if ($(this).find(".po-checkbox").not(":checked")) {
// enter your code here
} });
+1
欢迎来到*!请为您的代码添加说明,以便其他用户(他们可能正在寻找这些用户)知道您的代码的功能。 –
[jQuery的:查找所有未选中的复选框,如何]的可能重复(http://*.com/questions/1093350/jquery -find-所有非选择复选框,如何使用) –
的可能的复制[如何找到所有未选中的复选框?(https://*.com/questions/1093350/how-to-find-all-unselected-checkboxes ) – jacefarm