Home >Web Front-end >JS Tutorial >JQuery calls focus to make the text box gain focus (code attached)
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();
You need to pay attention to the difference between the two functions:
$("#id").focus();
$("#id")[0].focus();
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!