如何检查是否使用JavaScript选择单选按钮?我在HTML表单中有两个单选按钮。当其中一个字段为NULL时,将显示一个对话框。如何检查是否选择了单选按钮?
3 回答
阿晨1998
TA贡献2037条经验 获得超6个赞
<input type="radio" name="gender" id="gender_Male" value="Male" /><input type="radio" name="gender" id="gender_Female" value="Female" />
if(document.getElementById('gender_Male').checked) { //Male radio button is checked}else if(document.getElementById('gender_Female').checked) { //Female radio button is checked}
function atLeastOneRadio() { return ($('input[type=radio]:checked').size() > 0);}
gender
慕尼黑的夜晚无繁华
TA贡献1864条经验 获得超6个赞
var radios = document.getElementsByTagName('input');var value;for (var i = 0; i < radios.length; i++) { if (radios[i].type === 'radio' && radios[i].checked) { // get value, set checked flag or do whatever you need to value = radios[i].value; }}
添加回答
举报
0/150
提交
取消