label中for屬性

label 的 for 屬性規定label與哪一個表單元素綁定,若是用戶點擊 label 元素內的文本,則會切換到控件自己。html

可是label標籤for屬性的值只能是表單中id的值,而不能是類class的值spa


例如code

 

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



label標籤和表單控件相聯繫的方式htm

 

一、顯式形式ci

爲 <label> 標籤下的 for 屬性命名一個目標表單元素的 idget

 

<label for="SSN">Social Security Number:</label>
<input type="text" name="SocSecNum" id="SSn" />



二、隱式形式input

將表單控件做爲標記標籤的內容it

 

<label>Date of Birth: <input type="text" name="DofB" /></label>



參考資料:label for屬性   http://www.studyofnet.com/news/930.htmlio

相關文章
相關標籤/搜索