var el = document.getElementById("target");
this.setPlaceholder(el,'#666','#000');
/**
el: input 输入框;
color: 提示文字颜色
color2: 文本颜色
*/
function setPlaceholder(el,color,color2){
//判断浏览器是否支持placeholder
function isPlaceHolder(){
var input = document.createElement("input");
return "placeholder" in input;
}
if(!isPlaceHolder()){
var txt = el.getAttribute('placeholder');
el.onfocus = function(){
if(this.value == txt){
this.value = '';
this.style.color = color2 || '';
}
}
el.onblur = function(){
if(this.value == ''){
this.value = txt;
this.style.color = color;
}
}
el.value = txt;
el.style.color = color;
}
}