Calling the focus of the DOM object gives the text box focus

  • 2020-03-30 01:46:56
  • OfStack

Since the object obtained in JQuery is still a JQuery object, the use of focus() only makes the object obtain the onFocus() function, and it cannot be the object that gets the focus. Therefore, to make the object get the focus, the focus method of DOM object should be called, that is:
 
$("#id")[0].focus(); 

Note the difference between the two functions:
 
$("#id").focus(); 
$("#id")[0].focus(); 

The first is to increase the onFocus() time, and the second is to give the DOM object focus.

Related articles: