HTML5:如何使用“必需”的属性与“无线电”输入字段 [英] HTML5: How to use the "required" attribute with a "radio" input field
问题描述
我只是想知道如何在单选按钮上以正确的方式使用新的HTML5输入属性required。每个单选按钮字段都需要像下面这样的属性吗?或者只有一个领域得到它就足够了吗?
< input type =radioname =colorvalue =blackrequired =required/>
< input type =radioname =colorvalue =whiterequired =required/>
设置
设置属性至少需要一个输入。 要求
对于所有输入更清晰,但并非必要(除非动态生成单选按钮)。
单选按钮,它们必须都具有相同的 name
值。这允许一次只选择一个,并将所需的
应用于整个组。
< form>选择性别:< label>< input type =radioname =gendervalue =malerequired> Male< / label> < label>< input type =radioname =gendervalue =female>女< / label> < input type =submit>< / form>
<请注意:
为避免混淆是否需要单选按钮组,我们鼓励作者指定属性组中的所有单选按钮。的确,一般来说,鼓励作者避免首先没有任何初始检查控制的单选按钮组,因为这是用户不能返回的状态,因此通常被认为是不良的用户界面。 / p>
I am just wondering how to use the new HTML5 input attribute "required" the right way on radiobuttons. Does every radiobutton field need the attribute like below? Or is it sufficient if only one field gets it?
<input type="radio" name="color" value="black" required="required" />
<input type="radio" name="color" value="white" required="required" />
Set the required
attribute for at least one input of the radio group.
Setting required
for all inputs is more clear, but not necessary (unless dynamically generating radio-buttons).
To group radio buttons they must all have the same name
value. This allows only one to be selected at a time and applies required
to the whole group.
<form>
Select Gender:
<label><input type="radio" name="gender" value="male" required>Male</label>
<label><input type="radio" name="gender" value="female">Female</label>
<input type="submit">
</form>
Also take note of:
To avoid confusion as to whether a radio button group is required or not, authors are encouraged to specify the attribute on all the radio buttons in a group. Indeed, in general, authors are encouraged to avoid having radio button groups that do not have any initially checked controls in the first place, as this is a state that the user cannot return to, and is therefore generally considered a poor user interface.
这篇关于HTML5:如何使用“必需”的属性与“无线电”输入字段的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!