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

发布于 2024-08-30 19:06:34 字数 921 浏览 2 评论 0原文

抱歉,我对 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 教程,但没有成功。有人可以透露一些信息吗?

Sorry but im an absolute noob with javascript.

Ive made a form for a simple quiz but cant figure out how to make radio's only click once.

I can select two or three buttons as my answer. i want to change this.

<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/>

ive been rooting around w3shcools tutorials to no avail. can someone shed some light?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

[浮城] 2024-09-06 19:06:34

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

They should all have the same name attribute

简美 2024-09-06 19:06:34

您想要作为一个组的所有单选按钮的名称必须相同。

The name needs to be the same for all the radio buttons you want to act as a group.

陪你搞怪i 2024-09-06 19:06:34

试试这个

<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/>

Try this

<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/>
风向决定发型 2024-09-06 19:06:34

这是一个方法...
编辑不需要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>

这应该可以。

Here's an approach...
EDIT No Javascript needed, been awhile since I worked with radios.

In the body, you have this:

<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>

This should do it.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文