在 jQuery 中查找所有未选中的复选框 [英] Find all unchecked checkboxes in jQuery

查看:26
本文介绍了在 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" />

我可以收集所有选中复选框的值;我的问题是如何获取未选中复选框的所有值?我试过了:

I can collect all the values of checked checkboxes; my question is how can get all the values of unchecked checkboxes? I tried:

$("input:unchecked").val();

获得未选中复选框的值,但我得到了:

to get an unchecked checkbox's value, but I got:

语法错误,无法识别的表达式:未选中.

Syntax error, unrecognized expression: unchecked.

有人能解释一下这个问题吗?谢谢!

Can anybody shed a light on this issue? Thank you!

推荐答案

正如错误消息所述,jQuery 不包含 :unchecked 选择器.
相反,您需要反转 :checked 选择器:

As the error message states, jQuery does not include a :unchecked selector.
Instead, you need to invert the :checked selector:

$("input:checkbox:not(:checked)")

这篇关于在 jQuery 中查找所有未选中的复选框的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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