HTML DOM alt 属性

定义和用法

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

语法

  1. textObject.alt=alternate_text

实例

下面的例子可返回文本域的 alt 文本:

  1. <html>
  2. <body>
  3.  
  4. <form>
  5. Email: <input type="text" alt="Email input field" id="email" />
  6. </form>
  7.  
  8. <p>The alt text for the text field is:
  9. <script type="text/javascript">
  10. x=document.getElementById('email');
  11. document.write(x.alt);
  12. </script></p>
  13.  
  14. </body>
  15. </html>