<label> 標籤爲 input 元素定義標註(標記)。
label 元素不會向用戶呈現任何特殊效果。不過,它爲鼠標用戶改進了可用性。如果您在 label 元素內點擊文本,就會觸發此控件。就是說,當用戶選擇該標籤時,瀏覽器就會自動將焦點轉到和標籤相關的表單控件上。
<label> 標籤的 for 屬性應當與相關元素的 id 屬性相同。
例如:
<form>
<label>Male
<input type="radio" name="sex" id="male" /></label>
<br />
<label>Female
<input type="radio" name="sex" id="female" /></label>
</form>
點擊文本就會自動選中標籤內部的input框
也可以用for屬性來定位相應的input框
<form>
<label for="male">Male</label>
<input type="radio" name="sex" id="male" />
<br />
<label for="female">Female</label>
<input type="radio" name="sex" id="female" />
</form>