2
我一直在使用JavaScript占位符脚本来支持IE占位符。占位符 - 对于textarea输入
适用于输入类型=文本。但是,我该如何编写脚本的补充以支持textarea?
我的代码是:提前
function activatePlaceholders() {
var detect = navigator.userAgent.toLowerCase();
if (detect.indexOf("safari") > 0) return false;
var inputs = document.getElementsByTagName("input");
for (var i=0;i<inputs.length;i++) {
if (inputs[i].getAttribute("type") == "text") {
if (inputs[i].getAttribute("placeholder") && inputs[i].getAttribute("placeholder").length > 0) {
inputs[i].value = inputs[i].getAttribute("placeholder");
inputs[i].onclick = function() {
if (this.value == this.getAttribute("placeholder")) {
this.value = "";
}
return false;
}
inputs[i].onblur = function() {
if (this.value.length < 1) {
this.value = this.getAttribute("placeholder");
}
}
}
}
}
}
window.onload=function() {
activatePlaceholders();
}
感谢。