HTML DOM blur() 方法

定义和用法

blur() 方法用于从密码域移开焦点。

语法

  1. passwordObject.blur()

实例

下面的例子可设置或返回密码域的焦点:

  1. <html>
  2. <head>
  3. <script type="text/javascript">
  4. function setFocus()
  5. {
  6. document.getElementById('password1').focus()
  7. }
  8. function loseFocus()
  9. {
  10. document.getElementById('password1').blur()
  11. }
  12. </script>
  13. </head>
  14. <body>
  15.  
  16. <form>
  17. <input type="password" id="password1" value="thgrt456" />
  18. <input type="button" onclick="setFocus()" value="Set focus" />
  19. <input type="button" onclick="loseFocus()" value="Lose focus" />
  20. </form>
  21.  
  22. </body>
  23. </html>