使用 focus() 和 blur()

  1. <html>
  2. <head>
  3. <style type="text/css">
  4. a:active {color:green}
  5. </style>
  6.  
  7. <script type="text/javascript">
  8. function getfocus()
  9. {document.getElementById('myAnchor').focus()}
  10.  
  11. function losefocus()
  12. {document.getElementById('myAnchor').blur()}
  13. </script>
  14. </head>
  15.  
  16. <body>
  17. <a id="myAnchor" href="http://www.jishuchi.com">访问 jishuchi.com</a>
  18. <br /><br/>
  19. <input type="button" onclick="getfocus()" value="获得焦点">
  20. <input type="button" onclick="losefocus()" value="失去焦点">
  21. </body>
  22.  
  23. </html>