How to handle form focus events

一个新手
Release: 2017-09-19 10:23:40
Original
2179 people have browsed it

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!

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!