UI UI recommended jquery HTML5 implementation placeholder compatible password IE6HTML5 placeholder Property (how IE is compatible with placeholder properties)
2013-01-05 10:26:06| Category: Web Learning | Tags:html js ie placeholder | Report | Font size Big medium small subscription
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)
The default hint text is grayed out, and you can change the text style by using CSS:
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 () {
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 ~
This article originates from the http://lidrema.blog.163.com/blog/static/209702148201305101844932/