<html>
<input type="text" value="手机" style="color: #999;">
</html>
<script>
// 获取元素
var a = document.querySelector('input')
// 获取焦点事件 onfocus
a.onfocus = function(){
if(this.value === '手机'){
this.value = ''
}
this.style.color = '#333'
}
// 失去焦点事件 onblur
a.onblur = function(){
if(this.value === ''){
this.value = '手机'
}
this.style.color = '#999'
}
</script>
显示隐藏文本框内容
最新推荐文章于 2024-05-23 10:19:28 发布