Today we will take the text width as an example to talk about the focus event of the form. Other form types are similar
Focus: In order to distinguish the object input by the user, the browser can accept user input when an element has focus.
We can set focus to elements in some ways
1.tab
2, click
##3.js
Not all elements All can accept focus, and only elements that can respond to user operations have focus, such as forms, a tags
1.tab Needless to say, the browser gives us Done, we can use the tab key to change the focus at any time
2.Click to get focus onfocus
When we click on the form element, the element you clicked will gain focus and trigger onfocus
var aInp=document.getElementsByTagName('input'); for(var i=0;i Copy after login
Lost focus onblur
Usage: When we click outside. Our form loses focus and triggers onblur
3.js to gain focus. Use thefocusmethod to gain focus,blurMethod loses focus
aInp[1].focus();
Usage:Object.focusAt this time, the default focus is the second form (same as blur)
**Finally, a method is givenselect
select all the text content in the specified () element (the element that the user can input)---->Realize the copy function
The above is the detailed content of How to handle form focus events. For more information, please follow other related articles on the PHP Chinese website!