When jQuery1.7 meets the focus method

Source: Internet
Author: User

  If you must use the highest version of jquery, the easiest way to do this is to add a try/catch to Try{xxx.focus () when writing xxx.focus (); catch (e) {}

In jquery, there is a focus () method that sets the focal point of the object. In versions below 1.7, this method does not report an error, regardless of whether the object is a disabed state (only if the code that sets the focus is not valid when disabled), but in version 1.7, if the object is a disabled state, then it is reported directly when the focusing () method is invoked:   Error:can ' t move focus-control because it are invisible, not enabled, or of a type that does not accept the Focus.   means that an element that is not visible or unavailable does not get focus. (Special mention: IE9 is very NB, can automatically recognize this situation, in the IE9 will not be an error, but IE9 the following version of all hang. )     Code as follows: <!doctype html> <html>  <head>  <title> test </title>   <script src= "Jquery-1.7.min.js" type= "Text/javascript" ></script>  <!--<script src= " Jquery-1.4.4.min.js "type=" Text/javascript "></script>-->  <script type=" Text/javascript ">   function Fntest () {   //try{    $ ("#txt"). focus ();    //}catch (e) {}  }    </script>  </head>  <body>   <div>    <input type= "text" disabled= "Disabled" id= "txt"/>    <input type= "text" id= "Txt2"/>   <input type= "button" value= "Test" onclick= "fntest ()"/>   </div>  </body> < /html>   Although only a small change, but it is easy to create large cups, especially your JS code, after focus (), there are many other things to do:)   advice: If you must use the highest version of jquery, The easiest way to do this is to add a try/catch to the Try{xxx.focus () when writing xxx.focus (); catch (e) {}  

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.