label
元素為表單中的每個元素提供了一些上下文。它有局部屬性: for,form
。
以下代碼顯示了如何為用戶提供一些上下文。
<!DOCTYPE HTML>
<html>
<body>
<form method="post" action="http://example.com/form">
<p>
<label for="fave">Fruit: <input id="fave" name="fave" /></label>
</p>
<p>
<label for="name">Name: <input id="name" name="name" /></label>
</p>
<button>Submit Vote</button>
</form>
</body>
</html>
id
屬性添加到輸入元素,標(biāo)簽使用這些id作為標(biāo)簽元素上for
屬性的值。這就是如何將標(biāo)簽與輸入相關(guān)聯(lián),這使得屏幕閱讀器和其他技術(shù)的處理表格更加簡單。
更多建議: