小码哥的IT人生

HTML DOM alt 属性

JavaScript基础 2022-06-08 16:29:30小码哥的IT人生shichen

HTML DOM alt 属性

定义和用法

alt 属性可设置或返回在浏览器不支持确认按钮时显示的替代文本。

语法

submitObject.alt=alternate_text

实例

下面的例子可返回确认按钮的 alt 文本:

<html>
<body>
<form>
<input type="submit" alt="submit button" id="submit1" />
</form>
<p>The alt text for the submit button is:
<script type="text/javascript">
x=document.getElementById('submit1');
document.write(x.alt);
</script></p>
</body>
</html>

TIY

完整实例【返回确认按钮的 alt 文本】:

<html>
<body>
<form>
<input type="submit" alt="submit button" id="submit1" />
</form>
<p>The alt text for the submit button is:
<script type="text/javascript">
x=document.getElementById('submit1');
document.write(x.alt);
</script></p>
</body>
</html>

可以使用本站在线JavaScript测试工具测试上述代码运行效果:http://www.phpcodeweb.com/runjs.html

版权所有 © 小码哥的IT人生
Copyright © phpcodeweb All Rights Reserved
ICP备案号:苏ICP备17019232号-2  

苏公网安备 32030202000762号

© 2021-2024