【发布时间】:2025-12-05 08:50:01
【问题描述】:
我有几个复选框,每个组只有一个可选组件。复选框示例如下:
<label class="checkbox inline">
<input type="checkbox" id="question1option1" name="question1options" value="correct" onclick="SingleSelect('question1option',this)"> 1
</label>
<label class="checkbox inline">
<input type="checkbox" id="question1option2" name="question1options" value="wrong" onclick="SingleSelect('question1option',this)"> 2
</label>
<label class="checkbox inline">
<input type="checkbox" id="question1option3" name="question1options" value="wrong" onclick="SingleSelect('question1option',this)"> 3
</label>
<label class="checkbox inline">
<input type="checkbox" id="question2option1" name="question2options" value="correct" onclick="SingleSelect('question2option',this)"> 1
</label>
<label class="checkbox inline">
<input type="checkbox" id="question2option2" name="question2options" value="wrong" onclick="SingleSelect('question2option',this)"> 2
</label>
<label class="checkbox inline">
<input type="checkbox" id="question2option3" name="question2options" value="wrong" onclick="SingleSelect('question2option',this)"> 3
</label>
我有一个 javascript 函数,它通过传递单选按钮组(如下)拉出选择了哪个单选按钮,是否有等效的人可以帮助我获取选中复选框的值(每个组中只有一个') 请以类似的方式?
function getRadioValue (theRadioGroup)
{
for (var i = 0; i < document.getElementsByName(theRadioGroup).length; i++)
{
if (document.getElementsByName(theRadioGroup)[i].checked)
{
return document.getElementsByName(theRadioGroup)[i].value;
}
}
}
提前致谢。
【问题讨论】:
-
CSS3 支持根据本次讨论将单选设置为复选框:*.com/questions/279421/…
-
谢谢。我没有使用单选按钮的原因是它们看起来很难看,我似乎无法为所有浏览器找到解决方案,我认为您的链接有帮助,但在 Internet Explorer 中仍然不起作用?
标签: javascript html forms checkbox