【发布时间】:2015-02-08 14:16:25
【问题描述】:
这是我的 2 个单选按钮:
<input type="radio" name="sex" id="Button1" class="Button"/>
<input type="radio" name="sex" id="Button2" class="Button"/>
当我调用一个函数时:
document.getElementById('Button2').checked = false;
它取消选中 Button2。但我想通过使用类取消选中它
当函数包含:
document.getElementsByClassName('Button').checked = false;
它不会取消选中 Button2
为什么以及解决方案是什么?
谢谢。 :)
【问题讨论】:
-
两个按钮具有相同的类名,您希望代码如何工作?你必须给它一些东西来区分所需的按钮。
标签: javascript class button checkbox