点击输入文本框,隐藏文本框内容,并且颜色变深,输入框为空时恢复默认状态
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>显示隐藏文本框内容案例</title>
</head>
<body>
输入框:<input type="text" value="输入内容" >
<script>
//显示隐藏文本框内容案例
var btn = document.querySelector('input'); //获取元素
btn.onfocus = function() { //获得焦点事件
if(this.value == '输入内容') //等于默认值便改变
this.value = '';
this.style.color = '#333'; //文本框内容颜色变深
}
btn.onblur = function() { //失去焦点事件
if(this.value == '')
this.value = '输入内容';
this.style.color = '#999'; //文本框内容颜色变浅
}
</script>
</body>
</html>