通过js实现文本框的显示与隐藏,案例如下:
具体实现代码如下所示
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
</head>
<style>
input {
color: #999;
}
</style>
<body>
<input type="text" value="手机">
<script>
var text =document.querySelector('input')
//获得焦点
text .onfocus = function()
{
//默认值为手机 点击文本框后 文本框清空
if(this .value==='手机')
{
this.value=''
}
this.style.color='#333'
}
//失去焦点
text.onblur = function(){
if(this.value === '')
{
this.value='手机'
}
this.style.color='#999'
}
</script>
</body>
</html>