HTML DOM alt 属性

定义和用法

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

语法

  1. checkboxObject.alt=alternate_text

实例

下面的例子返回了 checkbox 的替代文本:

  1. <html>
  2. <body>
  3.  
  4. <form>
  5. I have a bike: <input id="bike" alt="bike" type="checkbox" name="Bike" />
  6. <br />
  7. I have a car: <input id="car" alt="car" type="checkbox" name="Car" />
  8. </form>
  9.  
  10. <p>The alt text for the checkboxes are:
  11. <script type="text/javascript">
  12. document.write(document.getElementById('bike').alt);
  13. document.write(" and ");
  14. document.write(document.getElementById('car').alt);
  15. </script></p>
  16.  
  17. </body>
  18. </html>