带输入或输入IN标签的HTML5结构标签

时间:2016-09-21 11:52:35

标签: html html5 code-structure

哪一个更合适?

第一个:

<div>
<label for="male">Male</label>
<input type="radio" name="gender" id="male" value="male">
</div>

第二个:

<label for="male">Male
<input type="radio" name="gender" id="male" value="male">
</label>

他们也在工作,但我不确定所有html结构的第二个选项是否合适。

2 个答案:

答案 0 :(得分:0)

这两个选项都是http://docs.grails.org/latest/guide/testing.html#functionalTesting的有效HTML,而第二种形式则不是强制性的。

使用您喜欢的任何一种。

答案 1 :(得分:0)

我会将输入放在这样的标签内,不会使用外部div包装器:

<label for="male">Male
   <input type="radio" name="gender" id="male" value="male">
</label>

以这种方式,当点击标签文本Male时,输入会获得焦点。