HTML5 has made many enhancements to the Web Form, such as input type, Form validation, and so on.
Placeholder is another property added by HTML5, and when input or textarea is set, the content of the value is displayed as a gray hint in the text box, and the hint text disappears when the text box gets the focus. In the past to achieve this effect is the use of JavaScript to control to achieve, Firefox, Google Chrome and other representations of its support, only ie there is vainly disobey sense Ah!
For example: <input id= "T1" type= "text" placeholder= "Please enter text"/>
Introduce a super strong let IE support placeholder property plug-in, but also compatible with other browsers do not support placeholder, the code is as follows:
The code is as follows:
$ (document). Ready (function () {
var doc=document,
Inputs=doc.getelementsbytagname (' input '),
supportplaceholder= ' placeholder ' in doc.createelement (' input '),
Placeholder=function (Input) {
var text=input.getattribute (' placeholder '),
Defaultvalue=input.defaultvalue;
if (defaultvalue== ') {
Input.value=text
}
Input.onfocus=function () {
if (Input.value===text)
{
This.value= "
}
};
Input.onblur=function () {
if (input.value=== ') {
This.value=text
}
}
};
if (!supportplaceholder) {
for (Var i=0,len=inputs.length;i<len;i++) {
var input=inputs[i],
Text=input.getattribute (' placeholder ');
if (input.type=== ' text ' &&text) {
Placeholder (input)
}
}
}
});
Directly copy the code down, save as a JS file reference can, no longer do any processing, super convenient!
Ex: This does allow IE's input to display the placeholder property, but if there is only one input on the page, if it is multiple input, if input is not filled in any value, Then its null input automatically fills the value of the placeholder into value, resulting in an error. For example:
The code is as follows:
<input type= "text" placeholder= "Input product Code" name= "Goodscode" id= "Goodscode" value= "123"/>
<input type= "text" placeholder= "Enter product name" Name= "Goodsname" id= "Goodsname" value= "Enter product name"/>
The solution is to judge in the background itself, perhaps in the above JS file to solve, and then study again ~!
Let IE support HTML5 's Placeholder property