检查是否选中了单选按钮 [英] Check if a radio button is checked jquery
本文介绍了检查是否选中了单选按钮的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有这个HTML:
<input type="radio" name="test" id="test" value="1"><br>
<input type="radio" name="test" id="test" value="2"><br>
<input type="radio" name="test" id="test" value="3"><br>
<input type="button" onclick="CreateJobDo">
页面加载后,将不会检查所有内容.我想使用jQuery检查按下按钮时是否选中了单选按钮之一.
When the page loads, none of them will be checked. I want to use jQuery to check if one of the radio buttons is checked when the button is pressed.
我有这个:
function CreateJobDo(){
if ($("input[@name=test]:checked").val() == 'undefined') {
// go on with script
} else {
// NOTHING IS CHECKED
}
}
但这不起作用.如何使其正常工作?
But this does not work. How to get it working?
推荐答案
尝试一下
if($('input:radio:checked').length > 0){
// go on with script
}else{
// NOTHING IS CHECKED
}
这篇关于检查是否选中了单选按钮的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文