HTML DOM click() 方法

定义和用法

click() 方法可模拟在按钮上的一次鼠标单击。

语法

  1. buttonObject.click()

实例

下面的例子将在 body onload 上模拟在按钮上的一次鼠标单击:

  1. <html>
  2. <head>
  3. <script type="text/javascript">
  4. function clickButton()
  5. {
  6. document.getElementById('button1').click()
  7. }
  8. function alertMsg()
  9. {
  10. alert("Button 1 was clicked!")
  11. }
  12. </script>
  13. </head>
  14. <body onload="clickButton()">
  15.  
  16. <form>
  17. <input type="button" id="button1" onclick="alertMsg()"
  18. value="Button 1" />
  19. </form>
  20.  
  21. </body>
  22. </html>