HTML DOM alt 属性
JavaScript基础 2022-06-08 16:09:38小码哥的IT人生shichen
HTML DOM alt 属性
定义和用法
alt 属性可设置或返回浏览器不支持 checkbox 时显示的替代文本。
语法
checkboxObject.alt=alternate_text
实例
下面的例子返回了 checkbox 的替代文本:
<html>
<body>
<form>
I have a bike: <input id="bike" alt="bike" type="checkbox" name="Bike" />
<br />
I have a car: <input id="car" alt="car" type="checkbox" name="Car" />
</form>
<p>The alt text for the checkboxes are:
<script type="text/javascript">
document.write(document.getElementById('bike').alt
);
document.write(" and ");
document.write(document.getElementById('car').alt
);
</script></p>
</body>
</html>
TIY
完整实例【返回 checkbox 的 alt 文本】:
<html>
<body>
<form>
I have a bike: <input id="bike" alt="bike" type="checkbox" name="Bike" />
<br />
I have a car: <input id="car" alt="car" type="checkbox" name="Car" />
</form>
<p>The alt text for the checkboxes are:
<script type="text/javascript">
document.write(document.getElementById('bike').alt);
document.write(" and ");
document.write(document.getElementById('car').alt);
</script></p>
</body>
</html>
可以使用本站在线JavaScript测试工具测试上述代码运行效果:http://www.phpcodeweb.com/runjs.html