這兩段代碼有何不同?
<form method="post" action="save.php">
? ? ? <label for="username">用戶(hù)名:</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">
? ? 賬戶(hù):?
<input type="text" name="myName"/>
<br>
密碼:?
<input type="password" name="pass"/>
有何大的差別,為何一個(gè)有l(wèi)abel for一個(gè)沒(méi)有?只是單純的語(yǔ)義化嗎?
2015-12-06
<label> 標(biāo)簽為 input 元素定義標(biāo)注(標(biāo)記)。
label 元素不會(huì)向用戶(hù)呈現(xiàn)任何特殊效果。不過(guò),它為鼠標(biāo)用戶(hù)改進(jìn)了可用性。如果您在 label 元素內(nèi)點(diǎn)擊文本,就會(huì)觸發(fā)此控件。就是說(shuō),當(dāng)用戶(hù)選擇該標(biāo)簽時(shí),瀏覽器就會(huì)自動(dòng)將焦點(diǎn)轉(zhuǎn)到和標(biāo)簽相關(guān)的表單控件上。
你只要點(diǎn)擊到Male或者Female,瀏覽器就會(huì)自動(dòng)將焦點(diǎn)轉(zhuǎn)到和標(biāo)簽相關(guān)的表單控件上。
2015-12-07
Label ?只是起到錨點(diǎn)作用