Home >Web Front-end >JS Tutorial >Example analysis of the method to focus the text box in JQuery_jquery
This article 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, not the object to obtain focus. Therefore, to enable the object to obtain focus, the focus method of the DOM object should be called. That is:
$("#id")[0].focus();
It is important to note 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 hope this article will be helpful to everyone’s jQuery programming.