Placeholder attribute, ie to its support expressed frustration, Firefox, Google Chrome said no pressure.
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. Previously, this effect was controlled by JavaScript to achieve:
<input id= "T1" type= "text" placeholder= "Please enter text"/>
Since placeholder is a new property, only a handful of browsers are currently supported, how can I detect if the browser supports it? (more HTML5/CSS3 feature detection can be accessed)
function hasplaceholdersupport () {< Span class= "PLN" >&NBSP; |
|
return ‘placeholder‘ in document.createElement( ‘input‘ ); |
The default hint text is grayed out, and you can change the text style by using CSS:
/*all*/
::-webkit-input-placeholder { color:#f00; }input:-moz-placeholder { color: #f00; }/ * Individual:webkit * /#field2::-webkit-input-placeholder { color: #00f; }#field3::-webkit-input-placeholder { color: #090; background: LightGreen; text-transform:uppercase; }#field4::-webkit-input-placeholder { font-style:Italic; text-decoration:overline; letter-spacing: 3px; color: #999; }/ * Individual:mozilla * /#field2:-moz-placeholder { color: #00f; } #field3 :-moz-placeholder {< Span class= "com" > color: #090; background:lightgreen; text-transform:uppercase; #field4:-moz-placeholder { font-style:Italic; text-decoration:overline; letter-spacing: 3px; color: #999; }
Compatible with other browsers that do not support placeholder:
Introduce a super strong let IE support placeholder property plug-in, the code is as follows:
$(Document).Ready(function(){
VarDoc=Document,
Inputs=Doc.getElementsByTagName(' Input '),
Supportplaceholder=' Placeholder 'InchDoc.CreateElement(' Input '),
Placeholder=function(Input){
VarText=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(VarI=0,Len=Inputs.Length;I<Len;I++){
VarInput=Inputs[i Text=input. ' 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 ~
"Work note five" HTML5 's Placeholder property (how IE is compatible with placeholder properties)