HTML 输出 for 属性
htmlweb developmentfront end technology更新于 2025/7/22 10:52:17
<output> 元素的 for 属性设置了计算结果与计算中使用的元素之间的关系。
语法如下:
<output for="id">
以上 id 是元素 ID,它设置了一个或多个元素的单独列表,每个元素之间用空格分隔。这些元素指定了计算结果与计算中使用的元素之间的关系。
现在让我们看一个实现 <output> 元素 for 属性的示例:
示例
<!DOCTYPE html> <html> <body> <h2>Result</h2> <form oninput="n.value=parseInt(p.value)+parseInt(q.value)+parseInt(r.value)">0 <input type="range" id="p" value="25">100+<input type="number" id="q" value="50">+<input type="number" id="r" value="50"> =<output name="n" for="p q r"></output> </form> </body> </html>
输出

现在,增加滑块,结果就会显示出来:

相关文章
有用资源
html 参考教程 - 该教程包含有关 html 的更多信息:https://www.cainiaomax.com/html/

