Home > Web Front-end > JS Tutorial > JQuery calls focus to make the text box gain focus (code attached)

JQuery calls focus to make the text box gain focus (code attached)

php中世界最好的语言
Release: 2018-04-26 14:09:44
Original
1686 people have browsed it

This article mainly introduces the method of getting the focus of the text box in JQuery, and analyzes the techniques of jQuery to get the focus of the text box with examples. Friends who need it can refer to the following

This example analyzes the method of making a text box focus in JQuery. Share it with everyone for your reference. The specific analysis is as follows:

Since the object obtained in JQuery is still a JQuery object, using focus() on it only causes the object to obtain the onFocus() function , the object cannot get focus, so to make the object get focus, you should call the focus method of DOM object , that is:

$("#id")[0].focus();
Copy after login
Copy after login

You need to pay attention to the difference between the two functions:

$("#id").focus();
Copy after login
$("#id")[0].focus();
Copy after login
Copy after login

The first is to increase the onFocus() time, and the other is to make the DOM object gain focus.

I believe you have mastered the method after reading the case in this article. For more exciting information, please pay attention to other related articles on the php Chinese website!

Recommended reading:

jquery implements the function of clicking the label to trigger the text box event

What are the parameters passing methods for jquery mobile

The above is the detailed content of JQuery calls focus to make the text box gain focus (code attached). 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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template