我的反馈表格出现问题。检查一组电台是否至少有一个选中
我只是想用jQuery或Javascript来验证,每一组的单选按钮始终一个按钮来选择,然后才能提交表单。
这是我的代码从我的form.html。
<form id='form' method='POST' action='validate.php'>
<table>
<!-- Table header -->
<tr>
<th> </th>
<th>Always</th>
<th>Often</th>
<th>Rarely</th>
<th>Never</th>
</tr>
<!-- Group One -->
<tr>
<th>Dummy Text 1</th>
<th><input class='radio' type='radio' name='item[0]' value='always'></th>
<th><input class='radio' type='radio' name='item[0]' value='often'></th>
<th><input class='radio' type='radio' name='item[0]' value='rarely'></th>
<th><input class='radio' type='radio' name='item[0]' value='never'></th>
</tr>
<!-- Group two -->
<tr>
<th>Dummy Text 2</th>
<th><input class='radio' type='radio' name='item[1]' value='always'></th>
<th><input class='radio' type='radio' name='item[1]' value='often'></th>
<th><input class='radio' type='radio' name='item[1]' value='rarely'></th>
<th><input class='radio' type='radio' name='item[1]' value='never'></th>
</tr>
<!-- End of table -->
</table>
</form>
<button class='buttons' onclick='subForm()' name='submit'>Send Feedback</button>
<script>
function subForm() {
//Code
}
</script>
但我不知道我应该用来检查是否检查无线电按钮。
我想document.getElementsByName
但这给我回不定值
由于提前
你有'getelementsbyclass'数组吗?或者你得到了什么输出? – Lino
噢,你的意思是'getElementsByClassName',因为你将无法正常工作:) – Lino
是的,我的意思是geElementsByClassName,我很懒惰,我通常依赖于我的开发环境/代码编辑器自动完成这样的事情对我来说。 –