HTML 屬性:for

for 屬性是 <label><output> 的允許屬性。當在 <label> 元素上使用時,它指示此標籤描述的表單元素。當在 <output> 元素上使用時,它允許在表示用於輸出的值的元素之間建立顯式關係。

試一試

用法

當用作 <label> 的屬性時,for 屬性的值是其相關聯的表單元素的 id

html
<label for="username">Your name</label> <input type="text" id="username" />

當用作 <output> 的屬性時,for 屬性的值是用於建立輸出的元素的 id 值的空格分隔列表。

html
<input type="range" id="b" name="b" value="50" /> +
<input type="number" id="a" name="a" value="10" /> =
<output name="result" for="a b">60</output>

示例

<label><output>元素頁面上檢視用法示例。

規範

規範
HTML 標準
# attr-label-for
HTML 標準
# attr-output-for

瀏覽器相容性

html.elements.label.for

BCD 表格僅在瀏覽器中載入

html.elements.output.for

BCD 表格僅在瀏覽器中載入