使用 focus() 和 blur()
- <html>
- <head>
- <style type="text/css">
- a:active {color:green}
- </style>
- <script type="text/javascript">
- function getfocus()
- {document.getElementById('myAnchor').focus()}
- function losefocus()
- {document.getElementById('myAnchor').blur()}
- </script>
- </head>
- <body>
- <a id="myAnchor" href="http://www.yousite.com">访问 yousite.com</a>
- <br /><br/>
- <input type="button" onclick="getfocus()" value="获得焦点">
- <input type="button" onclick="losefocus()" value="失去焦点">
- </body>
- </html>