如何检查单选按钮是否使用JQuery检查?
答
给定一组单选按钮:
<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
答
//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
答
检查这一个,太:
$(document).ready(function() {
if($("input:radio[name='yourRadioGroupName'][value='yourvalue']").is(":checked")) {
//its checked
}
});
答
这是最好的做法
$("input[name='radioGroup']:checked").val()
答
采取了一些答案一步 - 如果你下面,你可以检查无线电组中的任何元素已经检查:
if ($('input[name="yourRadioNames"]:checked').val()){
(选中)或if (!$('input[name="yourRadioNames"]:checked').val()){
(未选中)
[如何获得的单选按钮的值其中H的可能重复被检查,jquery](http://*.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://*.com/questions/2195125/check-of-specific-radio-button-is-checked) – 2012-07-20 14:31:53