测试是否用jQuery选中了复选框 [英] Testing if a checkbox is checked with jQuery
本文介绍了测试是否用jQuery选中了复选框的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
如果复选框被选中,那么我只需要获取值为1;
If the checkbox is checked, then I only need to get the value as 1; otherwise, I need to get it as 0. How do I do this using jQuery?
$(#ans)。val()
在这种情况下总是给我一个权利:
$("#ans").val()
will always give me one right in this case:
<input type="checkbox" id="ans" value="1" />
推荐答案
:checked')以确定是否已选中,然后相应地设置您的值。
Use .is(':checked')
to determine whether or not it's checked, and then set your value accordingly.
更多资讯。
这篇关于测试是否用jQuery选中了复选框的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文