在jquery中找到所有未选中的复选框 [英] find all unchecked checkbox in jquery

查看:878
本文介绍了在jquery中找到所有未选中的复选框的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个复选框列表:

 < input type =checkboxname =answerid = id_1'value =1/> 
< input type =checkboxname =answerid =id_2value =2/>
...
< input type =checkboxname =answerid =id_n'value =n/>
pre>

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

  $(input:unchecked)val(); 

获取未选中的复选框的值,但我有:


语法错误,无法识别的表达式:未选中。 / p>

可以让任何人了解这个问题吗?

解决方案

如错误消息所示,jQuery不包括:unchecked 选择器。

相反, :checked selector:

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


I have a list of checkboxes:

<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!

解决方案

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天全站免登陆