0
点赞
收藏
分享

微信扫一扫

隐藏显示文本框内容

 

<style>
input {
color: #777777;
}
</style>
</head>
<body>
<input type="text" value="手机" />
</body>
<script>
let ipt = document.querySelector("input");
ipt.onfocus = function () {
if (this.value === "手机") {
this.value = "";
}
// 获得焦点需要把文本框里面的文字颜色变黑
this.style.color = "black";
};
ipt.onblur = function () {
if (this.value === "") {
this.value = "手机";
}
// 失去焦点需要把文本框里面的文字颜色变浅色
this.style.color = "#777";
};
</script>
<!-- onfocus 获取焦点 -->
<!-- onblur失去焦点 -->

 


举报

相关推荐

0 条评论