HTML5 input type placeholder is not working in IE
I am using HTML5 for one of my project. There I am using input placeholder property to show some default text. It's not working in IE. Any solution for this?
Placeholder is not supported until IE 10.
http://caniuse.com/#feat=input-placeholder
You can use a polyfill to support it in IE.
如果你在你的项目中使用JavaScript,你可以添加这样的代码,它会通过javascript为你的输入提供一个占位符。
function supports_input_placeholder() {
var i = document.createElement('input');
return 'placeholder' in i;
}
if (!supports_input_placeholder()) {
var fields = document.getElementsByTagName('INPUT');
for (var i = 0; i < fields.length; i++) {
if (fields[i].hasAttribute('placeholder')) {
fields[i].defaultValue = fields[i].getAttribute('placeholder');
fields[i].onfocus = function () { if (this.value == this.defaultValue) this.value = ''; }
fields[i].onblur = function () { if (this.value == '') this.value = this.defaultValue; }
}
}
}
请参阅此主题的最佳答案,因为它有非常好的解释:为Internet Explorer输入占位符
链接地址: http://www.djcxy.com/p/70558.html上一篇: 重点关注输入时,Internet Explorer 10和11将删除占位符文本
下一篇: HTML5输入类型占位符在IE中不起作用