设置和移开文本域上的焦点

  1. <html>
  2. <head>
  3. <script type="text/javascript">
  4. function setFocus()
  5. {
  6. document.getElementById('text1').focus()
  7. }
  8. function loseFocus()
  9. {
  10. document.getElementById('text1').blur()
  11. }
  12. </script>
  13. </head>
  14. <body>
  15.  
  16. <form>
  17. <input type="text" id="text1" />
  18. <br />
  19. <input type="button" onclick="setFocus()" value="设置焦点" />
  20. <input type="button" onclick="loseFocus()" value="失去焦点" />
  21. </form>
  22.  
  23. </body>
  24. </html>