密码框变为文本框,且点击按钮查看密码明文
<DOCTYPE html>
<html>
<head>
<meta charset="UTF_8">
<title></title>
<style>
.box{
position: relative;
width: 400px;
border-bottom: 1px solid gray;
margin: 100px auto;
}
.box input{
width: 370px;
height: 30px;
border: 0;
outline: none;
}
.box img{
position: absolute;
top: 5px;
left: 360px;
width: 24px;
}
</style>
</head>
<body>
<div class="box">
<label for="">
<img src="img/4.jpg" alt="" id="eye">
</label>
<input type="password" name="" id="pwd">
</div>
<script>
//1.获取元素
var eye = document.getElementById("eye");
var password = document.getElementById("pwd");
//2.注册事件 处理程序
var flag = 1;
eye.onclick = function() {
if (flag == 1) {
password.type = "text";
eye.src = "img/open.png";
flag = 0;
} else {
password.type = "password";
eye.src = "img/close.png";
flag = 1;
}
}
</script>
</body>
</html>
浙公网安备 33010602011771号