1. 程式人生 > >HTML 標籤的 for 屬性

HTML 標籤的 for 屬性

<html>
<body>

<p>請點選文字標記之一,就可以觸發相關控制元件:</p>

<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>
</body>
</html>
顯式的聯絡:
<label for="SSN">Social Security Number:</label> <input type="text" name="SocSecNum" id="SSN" />

隱式的聯絡:
<label>Date of Birth: <input type="text" name="DofB" /></label>

總而言之就是可以通過lable for 與表單的元素的id進行繫結,點選lable就可以快速觸發繫結的相應的表單元素。