html5属性Placeholder(占位符)纯js版兼容 [ 新手入门 ]
<script>
function compatiblePlaceholder(){
if (!('placeholder' in document.createElement('input'))) {
var inputs = document.getElementsByTagName('input');
if (inputs.length != 0) {
for(var i=0; i<inputs.length; i++) {
var target = inputs[i];
if (target.placeholder != "") {
target.value = target.placeholder;
target.onfocus = function(){
if(this.value == this.placeholder)
this.value = '';
};
target.onblur = function(){
if(this.value == '')
this.value = this.placeholder;
};
}
}
}
}
}
window.onload = compatiblePlaceholder;
</script>
<body>
<input type="text" placeholder="占位符1"/>
<p>
<input type="text" placeholder="占位符2"/>
<p>
<input type="text" placeholder="占位符3"/>
</body>
共 4 条回复
skye 深圳
注册时间:2011-04-12
最后登录:2013-06-18
在线时长:0小时0分
最后登录:2013-06-18
在线时长:0小时0分
- 粉丝2
- 金钱575
- 威望0
- 积分575