模拟输入框

 
#txt{
color: gray;
}
 
 
<input type="text" value="请输入内容" id="txt"/>
 
document.getElementById("txt").onfocus=function(){
if(this.value=="请输入内容"){
this.value="";
this.style.color="black";
}
};
document.getElementById("txt").onblur=function(){
if(this.value.length==0){
this.value="请输入内容";
this.style.color="gray";
}
};

猜你喜欢

转载自www.cnblogs.com/hellocc/p/11242498.html