Compatible with placeholder

Source: Internet
Author: User

As we all know, ie9 is not compatible with the placeholder attribute, so we have customized a jquery plug-in, placeholder. js. The code for placeholder. JS is as follows:

/*** This control is compatible with ie9 or lower, and is specially designed for the * Author: quranjie * Date: */$ (function () that does not support the placeholder attribute below ie9 () {// If placeholder is not supported, use jquery to complete if (! Issuppplacplaceholder () {// traverses all input objects, except for the password box $ ('input '). not ("input [type = 'Password']"). each (function () {var self = $ (this); var val = self. ATTR ("Placeholder"); input (self, Val) ;});/* Special Handling of the password box * 1. create a text box * 2. switch between getting focus and losing focus */$ ('input [type = "password"] '). each (function () {var pwdfield = $ (this); var pwdval = pwdfield. ATTR ('placeholder'); var pwdid = pwdfield. ATTR ('id'); // rename the input ID to the original ID followed by 1pwdfield. after ('<input id = "' + pwdid + '1" type = "text" value = '+ pwdval + 'autocomplete = "off"/> '); vaR pwdplaceholder =$ ('#' + pwdid + '1'); pwdplaceholder. show (); pwdfield. hide (); pwdplaceholder. focus (function () {pwdplaceholder. hide (); pwdfield. show (); pwdfield. focus () ;}); pwdfield. blur (function () {If (pwdfield. val () = '') {pwdplaceholder. show (); pwdfield. hide () ;}}) ;}}); // determines whether the browser supports the placeholder attribute function issuppplacplaceholder () {var input = document. createelement ('input'); Return 'placeholder' in input;} // jquery replaces the processing function input (OBJ, Val) {var $ input = OBJ; var val = val; $ input. ATTR ({value: Val}); $ input. focus (function () {if ($ input. val () = Val) {$ (this ). ATTR ({value :""});}}). blur (function () {if ($ input. val () = "") {$ (this ). ATTR ({value: Val });}});}

Call method:

<HTML> This code is compatible with ie9 and earlier versions. jquery selects a stable version of 1.7.2. The code implementation takes into account multiple password input boxes on a page.


I want to create some part-time projects after work to earn some extra money. The main projects are Android, IOS, PHP, and website construction. These projects are especially good at Android, PHP, and website construction.

If you are interested, please send me a private email! If You Are the One, thank you!

Compatible with placeholder

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.