如何识别哪个单选按钮被接受? [英] How to identify which radio button is accepted?

查看:122
本文介绍了如何识别哪个单选按钮被接受?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何防止用户在使用单选按钮时能够选择多个选项?

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.

推荐答案

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

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

想想姓氏......举个例子,如果你有Bart,Lisa,Homer, Marge和Maggie,这个名字将是他们的姓氏:Simpson,其价值将会是上述名字:

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

这篇关于如何识别哪个单选按钮被接受?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆