测试是否使用 jQuery 选中复选框 [英] Testing if a checkbox is checked with jQuery
本文介绍了测试是否使用 jQuery 选中复选框的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
如果勾选了复选框,那么我只需要获取值为1;否则,我需要将其设为 0.如何使用 jQuery 执行此操作?
$("#ans").val()
在这种情况下总是会给我一个权利:
解决方案
使用 .is(':checked')
来判断它是否被选中,然后相应地设置你的值.>
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()
will always give me one right in this case:
<input type="checkbox" id="ans" value="1" />
解决方案
Use .is(':checked')
to determine whether or not it's checked, and then set your value accordingly.
这篇关于测试是否使用 jQuery 选中复选框的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文