仿京东登录显示隐藏密码
D:\开发\Vue项目\Vue2学习\html练习\仿京东显示隐藏密码.html
<!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>仿京东登录显示隐藏密码</title>
<style>
.box {
position: relative;
width: 400px;
margin: 100px auto;
border-bottom: 1px solid #ccc;
}
.box input {
width: 370px;
height: 30px;
border: 0;
outline: none;
}
.box img {
position: absolute;
/* border: 1px solid; */
width: 20px;
top: 5px;
right: 0%;
}
</style>
</head>
<body>
<div class="box">
<label for="">
<img src="../images/闭眼睛.png" alt="" id="eye">
</label>
<input type="password" name="" id="pwd"></input>
</div>
<script>
//1、获取元素
var eye = document.getElementById('eye');
var pwd = document.getElementById('pwd');
//2、注册事件,处理程序
var flag = 0;
eye.onclick = function() {
//点击一次,flag 一定要变化
if (flag == 0) {
pwd.type = "text";
this.src = '../images/眼睛.png'
flag = 1;
} else {
pwd.type = "password";
this.src = '../images/闭眼睛.png'
flag = 0;
}
}
</script>
</body>
</html>
图片文件
D:\开发\Vue项目\Vue2学习\images\眼睛.png
D:\开发\Vue项目\Vue2学习\images\闭眼睛.png
![闭眼睛](https://images.cnblogs.com/cnblogs_com/blogs/756747/galleries/2322792/o_230701043442_%E7%9C%BC%E7%9D%9B.png)
![眼睛](https://images.cnblogs.com/cnblogs_com/blogs/756747/galleries/2322792/o_230701043349_%E9%97%AD%E7%9C%BC%E7%9D%9B.png)