我在一个组中有两个单选按钮,我想检查单选按钮是否选中使用JQuery,怎么样?如何检查单选按钮是否使用JQuery检查?
18
A
回答
42
给定一组单选按钮:
<input type="radio" id="radio1" name="radioGroup" value="1">
<input type="radio" id="radio2" name="radioGroup" value="2">
您可以测试是否如下特定的人使用jQuery的检查:
if ($("#radio1").prop("checked")) {
// do something
}
// OR
if ($("#radio1").is(":checked")) {
// do something
}
// OR if you don't have ids set you can go by group name and value
// (basically you need a selector that lets you specify the particular input)
if ($("input[name='radioGroup'][value='1']").prop("checked"))
你可以得到的当前值在组中检查一个如下:
$("input[name='radioGroup']:checked").val()
+0
非常感谢。这非常有用 – user1557020 2014-08-10 07:22:21
7
//the following code checks if your radio button having name like 'yourRadioName'
//is checked or not
$(document).ready(function() {
if($("input:radio[name='yourRadioName']").is(":checked")) {
//its checked
}
});
+1
描述你的代码实际上会有帮助(对于提问者 - 不是我) – BeRecursive 2012-01-04 12:25:17
0
检查这一个,太:
$(document).ready(function() {
if($("input:radio[name='yourRadioGroupName'][value='yourvalue']").is(":checked")) {
//its checked
}
});
2
这是最好的做法
$("input[name='radioGroup']:checked").val()
0
采取了一些答案一步 - 如果你下面,你可以检查无线电组中的任何元素已经检查:
if ($('input[name="yourRadioNames"]:checked').val()){
(选中)或if (!$('input[name="yourRadioNames"]:checked').val()){
(未选中)
相关问题
- 1. 如何检查单选按钮是否使用jquery进行检查
- 2. 如何检查组中是否检查了单选按钮
- 3. Jquery单选按钮检查
- 4. 检查单选按钮| jQuery
- 5. 如何检查单选按钮是否使用javascript选择
- 6. 如何检测是否使用jQuery检查某个单选按钮?
- 7. 使用JQuery来检查组中是否没有单选按钮被检查
- 8. 如何检查单选按钮是否使用JavaScript进行检查?
- 9. 如何聆听是否使用ExtJS检查单选按钮?
- 10. 检查每个单选按钮是否被检查的JavaScript?
- 11. jQuery addClass如果单选按钮检查
- 12. 用JQuery检查单选按钮
- 13. 检查单选按钮值检查
- 14. 找出是否用JQuery检查单选按钮?
- 15. 检查单选按钮是否被选中jQuery
- 16. 功能,检查单选按钮是否检查/未检查在JavaScript
- 17. 如何检查单选按钮是否通过xquery选择
- 18. 如何检查是否复选框/单选按钮在PHP
- 19. 如何检查是否选择了单选按钮之一?
- 20. 如何检查是否没有单选按钮被选中?
- 21. 如何检查单选按钮是否被选中
- 22. jQuery:检查是否在不同组中有未经检查的单选按钮
- 23. 检查是否所有单选按钮都在jQuery的数据表检查
- 24. 如何检查单选按钮是否具有'检查'属性原型
- 25. 带有jQuery的单选按钮检查
- 26. jquery单选按钮检查属性?
- 27. jQuery:单选按钮没有被检查
- 28. 如何检测jquery中单选按钮的检查状态?
- 29. 检查单选按钮(笨)
- 30. 从检查单选按钮
[如何获得的单选按钮的值其中H的可能重复被检查,jquery](http://stackoverflow.com/questions/1083644/how-to-get-the-values-of-the-radio-button-which-has-been-checked-jquery) – matino 2012-01-04 10:22:03
可能重复[特定单选按钮的检查被选中](http://stackoverflow.com/questions/2195125/check-of-specific-radio-button-is-checked) – 2012-07-20 14:31:53