If you must use the highest version of jQuery, the most convenient way is to write xxx. add a trycatch to focus () and change it to try {xxx. focus ();} catch (e) {} There is a focus () method in jQuery that can set the focus of an object. In versions earlier than 1.7, whether the object is in the disabed state or not, this method will not report an error (only when the focus is set to disabled, the code that sets the focus is invalid), but in version 1.7, if the object is in the disabled status, when the focus () method is called, an exception is 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.
Meaning:Invisible or unavailable elements cannot obtain the focus. (In particular, IE9 is very NB and can automatically identify this situation. In IE9, no error is reported, but IE9 or earlier versions are all suspended .)
The Code is as follows:
Test