The focus is the cursor. The focus is a small vertical line flashing in the page screen. The cursor can be obtained by clicking the mouse. The Tab key can switch the focus according to the set Tabindex. In JavaScriptongoing, it can be obtained through the [focus()] method. Focus, remove the focus through the [blur()] method.
The operating environment of this article: Acer S40-51, HBuilderX.3.0.5 version, Windows10 Home Chinese version
Related free learning recommendations: javascript video tutorial
Focus is the cursor, and the focus is the small vertical line that flashes on the page screen. Click the mouse to get the cursor, and the Tab key can switch focus according to the set Tabindex. In JavaScript, you can obtain the focus through the focus() method and remove the focus through the blur() method.
Get focus:
focus()
The method is used to give focus to the checkbox.
Syntax:
checkboxObject.focus()
Losing focus:
blur()
The method is used to remove the focus from the radio button.
Syntax;
radioObject.blur()
Example:
The following example can set or remove the focus on the radio button:
<!DOCTYPE html> <html> <head> <meta charset="utf-8"> <script type="text/javascript"> function setFocus() { document.getElementById('check1').focus() } function loseFocus() { document.getElementById('check1').blur() } </script> </head> <body> <form> <input type="text" id="check1" /> <br /><br /> <input type="button" onclick="setFocus()" value="获取焦点" /> <input type="button" onclick="loseFocus()" value="移开焦点" /> </form> </body> </html>
Rendering:
If you want to know more about programming learning, please pay attention to the php training column!
The above is the detailed content of what is the focus. For more information, please follow other related articles on the PHP Chinese website!