這兩段代碼有何不同?
<form method="post" action="save.php">
? ? ? <label for="username">用戶名:</label>
? ? ? <input type="text" ?name="username" id="username" value="" />
? ? ? <label for="pass">密碼:</label>
? ? ? <input type="password" ?name="pass" id="pass" value="" /> ? ?
? ? ? <input type="submit" value="確定" ?name="submit" />
</form> ?
和
<form ?method="post" action="save.php">
? ? 賬戶:?
<input type="text" name="myName"/>
<br>
密碼:?
<input type="password" name="pass"/>
有何大的差別,為何一個有label for一個沒有?只是單純的語義化嗎?
2015-12-06
<label> 標簽為 input 元素定義標注(標記)。
label 元素不會向用戶呈現任何特殊效果。不過,它為鼠標用戶改進了可用性。如果您在 label 元素內點擊文本,就會觸發此控件。就是說,當用戶選擇該標簽時,瀏覽器就會自動將焦點轉到和標簽相關的表單控件上。
你只要點擊到Male或者Female,瀏覽器就會自動將焦點轉到和標簽相關的表單控件上。
2015-12-07
Label ?只是起到錨點作用