focus() 方法用于为元素设置焦点(如果可以设置)。
提示:使用 blur() 方法来移除元素焦点。
方法 | 谷歌 | IE | 火狐 | 苹果 | opera |
---|---|---|---|---|---|
focus() | Yes | Yes | Yes | Yes | Yes |
HTMLElementObject.focus()
None |
返回值: | 没有返回值 |
---|
为 <a> 元素设置焦点:
<!DOCTYPE html> <html> <title>Web176教程网(web176.com)</title> <head> <style> a:focus, a:active { color: green; } </style> </head> <body> <a id="myAnchor" href="https://www.web176.com" target="_blank">访问Web176教程网</a> <p>点击按钮设置或移除以上链接的焦点。</p> <input type="button" >