Home  >  Article  >  Web Front-end  >  Example analysis of the method to focus the text box in JQuery_jquery

Example analysis of the method to focus the text box in JQuery_jquery

WBOY
WBOYOriginal
2016-05-16 16:11:57982browse

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.

Statement:
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