我不明白爲什麼你會來包裝標籤的元素周圍,使之獲得。 但是你可以做任何一種方式:環繞四周,或者有一個for=""
匹配元素的id(你的select
)。
所以,如果你環繞,你不需要for=
,所以這樣的事情應該工作:
<div style="width:895px; max-width:100%; text-align:right;">
<label>
Select:
<select id="view" onchange="toggleElement(this)">
<option value="All">All</option>
<option value="Tenant">A</option>
<option value="Landlord">B</option>
</select>
</label>
</div>
但你也可以使用一個正確for
,而不是包裝的。該for
必須在這種情況下,id
匹配:
<div style="width:895px; max-width:100%; text-align:right;">
<label for="view">
Select:
</label>
<select id="view" onchange="toggleElement(this)">
<option value="All">All</option>
<option value="Tenant">A</option>
<option value="Landlord">B</option>
</select>
</div>
編輯:你可以看到通過驗證你的HTML什麼是錯的: http://validator.nu/
Error: Bad value select document type for attribute for on element label: An ID must not contain whitespace.
:right;">↩<label for="select document type">↩Selec
Error: Any select descendant of a label element with a for attribute must have an ID value that matches that for attribute.
↩Select: ↩<select id="view" onchange="toggleElement(this)">↩<opti
Error: The for attribute of the label element must refer to a form control.
:right;">↩<label for="select document type">↩Selec
上面提到的3個錯誤是糟糕的一切都是因爲for
屬性。
LABEL標籤不包裝控件。他們應該在他們旁邊。 –
所以它會包裝單詞選擇:? – user3219859
正確。請參閱:http://alistapart.com/article/prettyaccessibleforms –