首页 > 技术文章 > 模拟输入框

hellocc 2019-07-25 10:09 原文

 
#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";
}
};

推荐阅读