Input placeholder compatible with IE10 below

Source: Internet
Author: User

The code is as follows:

 if(/msie/.test (Navigator.userAgent.toLowerCase ()) && $.browser.version.slice (0,3) <Ten) {        $('Input[placeholder]'). each (function () {varInput = $ ( This); $ (input). val (Input.attr ('placeholder')); $ (input). focus (function () {if(Input.val () = = Input.attr ('placeholder') {input.val ("');               }        }); $ (input). blur (function () {if(Input.val () = ="'|| Input.val () = = Input.attr ('placeholder') {input.val (input.attr ('placeholder'));        }            });          }); }    

which

$.brower.msie =  /msie/.test (navigator.userAgent.toLowerCase ())  //$.brower jquery1.90 above is removed

Jquery 1.9. More than 0 version extensions use the $.browser method


Because of jquery 1.9.0 or later jquery removed support for $.browser and used $.support to determine the browser type. Cause many previous plugins to error

"Uncaught typeerror:cannot Read Property ' Msie ' of undefined".

There are many solutions on the Internet, such as:

To determine the browser type:

[HTML]View PlainCopy
    1. <span style= "White-space:pre" >     </span>$
    2.     $
    3.     $.browser.opera = /opera/.test ( Navigator.userAgent.toLowerCase ());   
    4.     $ .browser.msie = /msie/.test (Navigator.userAgent.toLowerCase ());  


The expression after the number returns is True/false, which can be used to replace the original $.browser.msie and so on.


Check if it is IE6:
Old
[HTML]View PlainCopy
    1. <span style="White-space:pre"> </span>if ($.browser.msie && 7 > $.browser.version) {}  
New
[HTML]View PlainCopy
    1. <span style="White-space:pre"> </span>if (' undefined ' = = typeof ( document.body.style.maxHeight)) {}
Check if it is IE 6-8:
[HTML]View PlainCopy
    1. <span style="White-space:pre"> </span>if (!$.support.leadingwhitespace) {}

**************************************************************************

The idea below is to use jquery's inheritance mechanism to extend the jquery 1.11.1 version to support the $.browser method, which is compatible with the previous component's purpose.

[HTML]View PlainCopy
  1. Jquery.extend ({
  2. Browser:function ()
  3. {
  4. Var
  5. Rwebkit =/(WebKit) \ ([\w.] +)/,  
  6. Ropera =/(opera) (?:. *version)? [ \/] ([\w.] +)/,  
  7. Rmsie =/(MSIE) ([\w.] +)/,  
  8. Rmozilla =/(Mozilla) (?:. * RV): ([\w.] +))?/,      
  9. browser = {},
  10. ua = window.navigator.userAgent,
  11. Browsermatch = uamatch (UA);
  12. if (Browsermatch.browser) {
  13. Browser[browsermatch.browser] = true;
  14. browser.version = browsermatch.version;
  15. }
  16. return {Browser:browser};
  17. },
  18. });
  19. function Uamatch (UA)
  20. {
  21. ua = ua.tolowercase ();
  22. var match = rwebkit.exec (UA)
  23. || Ropera.exec (UA)
  24. || Rmsie.exec (UA)
  25. || Ua.indexof ("compatible") < 0 && rmozilla.exec (UA)
  26. || [];
  27. return {
  28. BROWSER:MATCH[1] | | "",
  29. VERSION:MATCH[2] | | "0"
  30. };
  31. }

Save the above code for jquery-browser.js use.

Input placeholder compatible with IE10 below

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.