我在我的表单中有许多单选按钮,具有不同的名称组。我得到单个无线电组值,但我想获得表单的所有组单选按钮值。 这里是我的代码,我得到反馈单选按钮值,而不是状态。请帮帮我。在此先感谢无法获得多个单选按钮的价值
<html>
<head>
<script type="text/javascript">
function myFunction() {
var radioButtons = document.getElementsByName("feedback","status");
for (var x = 0; x < radioButtons.length; x ++) {
if (radioButtons[x].checked) {
alert("You checked " + radioButtons[x].id);
alert("Value is " + radioButtons[x].value);
}
}
}
</script>
</head>
<body>
<input type="radio" name="feedback" id="outstanding" value="1" />Outstanding
<input type="radio" name="feedback" id="good" value="2" />Good
<input type="radio" name="feedback" id="accept" value="3" />Acceptable
<input type="radio" name="status" id="done" value="1" />Done
<input type="radio" name="status" id="nothing" value="2" />Nothing
<input type="radio" name="status" id="work" value="3" />Work
<button class="btn btn-primary pull-right place-order-button" name="submit" value="submit" onclick="myFunction()" type="submit" >Finish</button>
</body>
</html>
https://fiddle.jshell.net/nady/711evwd8/
'getElementsByName()'只接受一个字符串参数 –
document.getElementsByName接受一个参数,因此 “状态” 被忽略...尝试querySelectorAll作为替代 –