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