Home >Web Front-end >JS Tutorial >When jQuery1.7 encounters problems with the focus method_jquery
There is a focus() method in jQuery that can set the focus of an object. In versions below 1.7, this method will not report an error regardless of whether the object is disabled (but when it is disabled, the code for setting the focus is invalid). But in version 1.7, if the object is in the disabled state, when the focus() method is called, an exception will be reported directly:
Error: Can't move focus to the control because it is invisible, not enabled, or of a type that does not accept the focus.
means: Invisible or unavailable elements cannot gain focus. (Special mention: IE9 is very cool and can automatically recognize this situation. It will not report an error under IE9, but versions below IE9 will all hang.)
Suggestion:
If you must use the highest version of jQuery, the easiest way is to add a try/catch when writing xxx.focus(). Become try{xxx.focus();}catch(e){}