In JavaScript, focus means "focus". The focus() method can be used to set focus for an element, and the syntax is "HTMLElementObject.focus()".
The operating environment of this tutorial: Windows 10 system, JavaScript version 1.8.5, Dell G3 computer.
The focus() method is used to set focus for an element (if it can be set).
Tip: Use the blur() method to remove element focus.
The syntax is:
HTMLElementObject.focus()
The example is as follows:
<!DOCTYPE html> <html> <head> <style> a:focus, a:active { color: green; } </style> </head> <body> <a id="myAnchor" href="//www.php.cn">获取焦点</a> <p>点击按钮设置或移除以上链接的焦点。</p> <input type="button" onclick="getfocus()" value="获取焦点"> <input type="button" onclick="losefocus()" value="移除焦点"> <script> function getfocus() { document.getElementById("myAnchor").focus(); } function losefocus() { document.getElementById("myAnchor").blur(); } </script> </body> </html>
Output result:
Related recommendations: javascript learning tutorial
The above is the detailed content of What does focus mean in javascript. For more information, please follow other related articles on the PHP Chinese website!