如何确定接受哪个单选按钮?

发布于 2024-09-08 00:49:03 字数 393 浏览 0 评论 0原文

如何确定接受哪个单选按钮?

当我使用单选按钮时,如何防止用户选择多个选项?

<input type='radio' name='one'>option1<br />
<input type='radio' name='two'>option2<br />
<input type='radio' name='three'>option3<br />
<input type='radio' name='four'>option4<br />
<input type='radio' name='five'>option5<br />

这就是我使用的代码,感谢您的阅读。

How can I identify which radio button is accepted?

How do I prevent a user being able to select multiple options when I use radio buttons?

<input type='radio' name='one'>option1<br />
<input type='radio' name='two'>option2<br />
<input type='radio' name='three'>option3<br />
<input type='radio' name='four'>option4<br />
<input type='radio' name='five'>option5<br />

Thats the code I use, thanks for reading.

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

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

发布评论

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

评论(4

情何以堪。 2024-09-15 00:49:03

您需要使用“name”属性将它们连接在一起,使用 value 属性为它们提供不同的值。

<input type="radio" name="number" value="one" /> One<br />
<input type="radio" name="number" value="two" /> Two<br />
<input type="radio" name="number" value="three" /> Three<br />

将名字视为姓氏...例如,如果您有 Bart、Lisa、Homer、Marge 和 Maggie,则名称将是他们的姓氏:Simpson,值将是上述名称:

<input type="radio" name="Simpson" value="Bart" /> Bart<br />
<input type="radio" name="Simpson" value="Lisa" /> Lisa<br />
<input type="radio" name="Simpson" value="Marge" /> Marge<br />
<input type="radio" name="Simpson" value="Homer" /> Homer<br />
<input type="radio" name="Simpson" value="Maggie" /> Maggie<br />

You need to use the "name" attribute to tie them all together, use the value attribute to give them different values.

<input type="radio" name="number" value="one" /> One<br />
<input type="radio" name="number" value="two" /> Two<br />
<input type="radio" name="number" value="three" /> Three<br />

Think of name as last name... For example, if you had Bart, Lisa, Homer, Marge and Maggie, the name would be their last name: Simpson, the value would be the said names:

<input type="radio" name="Simpson" value="Bart" /> Bart<br />
<input type="radio" name="Simpson" value="Lisa" /> Lisa<br />
<input type="radio" name="Simpson" value="Marge" /> Marge<br />
<input type="radio" name="Simpson" value="Homer" /> Homer<br />
<input type="radio" name="Simpson" value="Maggie" /> Maggie<br />
橙幽之幻 2024-09-15 00:49:03

你应该给他们起同样的名字

you should give them the same name

春花秋月 2024-09-15 00:49:03

我猜名称/值对的顺序也很重要。名称应该出现在顺序之前

Also the order of name/value pair matter's I guess.Name should appear before the order

墨小沫ゞ 2024-09-15 00:49:03

我知道!这样做:

<label><input type="radio" name="a">1</label>
<label><input type="radio" name="a">2</label>
<label><input type="radio" name="a">3</label>

为“名称”属性赋予所有相同的值。您添加单选按钮的名称

I know! Do like this:

<label><input type="radio" name="a">1</label>
<label><input type="radio" name="a">2</label>
<label><input type="radio" name="a">3</label>

Give everything same value for 'name' attribute. You add the name for the radio buttons

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