在javascript中使复选框可点击一次?

时间:2010-04-28 14:01:36

标签: javascript radio-button

很抱歉,但我是一个绝对的菜鸟javascript。

我为一个简单的小测验做了一个表格,但是无法弄清楚如何只用一次点击广播。

我可以选择两个或三个按钮作为我的答案。我想改变它。

<form name = "Beginners Quiz">

<p>Film speed refers to:</p>
<p><input type="radio" name="Answer 1" id="Answer1" value = "a" onclick =  "recordAnswer(1,this.value"/>How long it takes to develop film. <br/>
<p><input type="radio" name="Answer 2" id="Answer2" value = "b" onclick = "recordAnswer(1,this.value"/>How fast film moves through film-transport system.  <br/>
<p><input type="radio" name="Answer 3" id="Answer3" value = "c" onclick = "recordAnswer(1,this.value"/> How sensitive the film is to light.  <br/>
<p><input type="radio" name="Answer 4" id="Answer4" value = "d" onclick = "recordAnswer(1,this.value"/> None of these makes sense. <br/>

我一直在围绕w3shcools教程无济于事。有人可以解释一下吗?

4 个答案:

答案 0 :(得分:3)

它们都应具有相同的name属性

答案 1 :(得分:3)

您希望充当群组的所有单选按钮的名称必须相同。

答案 2 :(得分:2)

试试这个

<p>Film speed refers to:</p>
<p><input type="radio" name="Answer" id="Answer1" value = "a" onclick =  "recordAnswer(1,this.value"/>How long it takes to develop film. <br/>
<p><input type="radio" name="Answer" id="Answer2" value = "b" onclick = "recordAnswer(1,this.value"/>How fast film moves through film-transport system.  <br/>
<p><input type="radio" name="Answer" id="Answer3" value = "c" onclick = "recordAnswer(1,this.value"/> How sensitive the film is to light.  <br/>
<p><input type="radio" name="Answer" id="Answer4" value = "d" onclick = "recordAnswer(1,this.value"/> None of these makes sense. <br/>

答案 3 :(得分:0)

这是一种方法...... 编辑不需要Javascript,自从我使用无线电以来已经有一段时间了。

在体内,你有这个:

<form name="beginners_quiz">
<fieldset id="radios"><legend id="quiz">Film speed refers to:</legend>
<input type="radio" name="answer" id="Answer1" value="a" onclick="recordAnswer(1,this.value);" />How long it takes to develop film.<br/>
<input type="radio" name="answer" id="Answer2" value="b" onclick="recordAnswer(1,this.value);" />How fast film moves through film-transport system.<br/>
<input type="radio" name="answer" id="Answer3" value="c" onclick="recordAnswer(1,this.value);" />How sensitive the film is to light.<br/>
<input type="radio" name="answer" id="Answer4" value="d" onclick="recordAnswer(1,this.value);" />None of these makes sense.<br/>
</fieldset>
</form>

这应该这样做。