<label> 要素と一緒に使用すると、for 属性は、ラベルがバインドされているフォーム要素を指定します。
<output> 要素と一緒に使用すると、for 属性は、計算の結果と計算に使用した要素との関係を指定します。
for 属性は、以下の要素で使用することができます:
要素 | 属性 |
---|---|
<label> | for |
<output> | for |
3 つのラベル付きラジオボタン:
<form action="demo_form.html">
<label for="male">Male</label>
<input type="radio"
name="gender" id="male" value="male"><br>
<label
for="female">Female</label>
<input type="radio" name="gender"
id="female" value="female"><br>
<label for="other">Other</label>
<input type="radio" name="gender" id="other" value="other"><br><br>
<input type="submit" value="Submit">
</form>
Try it Yourself ❯
計算を実行し、<output> 要素に結果を表示します:
<form oninput="x.value=parseInt(a.value)+parseInt(b.value)">0
<input type="range" id="a" value="50">100
+<input type="number" id="b" value="50">
=<output name="x" for="a b"></output>
</form>
Try it Yourself ❯
for
属性は、要素ごとに以下のブラウザがサポートしています。
要素 | |||||
---|---|---|---|---|---|
label | Yes | Yes | Yes | Yes | Yes |
output | 10.0 | サポートなし | 4.0 | 5.1 | 11.0 |