<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>
显示隐藏文本框内容
猜你喜欢
转载自blog.csdn.net/m0_59735348/article/details/124475674
今日推荐
周排行