0

我认为这会起作用,但如果为空,它不会返回 false。有什么建议么?

var radioButtons = document.getElementsByName("Vehicle");
for (var i = 0; i < radioButtons.length; i++) {
if (radioButtons[i].checked) {
    console.log("radioButton " + i + ": " + radioButtons[i].value);
}
}

来源:http ://www.vbforums.com/showthread.php?679670-RESOLVED-How-to-use-Javascript-to-get-the-value-of-a-radio-button

4

1 回答 1

1

因为所有具有互斥选择的单选按钮都具有相同的name......并且没有两个元素应该具有相同的id. 并且使用id所有按钮的 s 是乏味的。

于 2013-06-06T07:21:56.303 回答