<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title></title>
<script src="http://code.jquery.com/jquery-latest.js"></script>
<style>
.box {
position: relative;
width: 400px;
border-bottom: 1px solid #ccc;
margin: 100px auto;
}
.box input {
width: 370px;
height: 30px;
border: 0;
outline: none;
}
.box img {
position: absolute;
top: 10px;
right: 30px;
width: 16px;
}
</style>
</head>
<body>
<div class="box">
<label for="">
<img src="img/闭眼_线.png" / alt="" id="eye">
</label>
<input type="password" name="" id="pwd" />
</div>
<script>
//1.获取元素
var eye = document.getElementById('eye');
var pwd = document.getElementById('pwd');
//2.注册事件 处理程序
var flag = 0;
eye.onclick = function() {
if (flag == 0) {
pwd.type = 'text';
eye.src = 'img/睁眼.png';
flag = 1; //复制操作
} else {
pwd.type = 'password';
eye.src = 'img/闭眼_线.png';
flag = 0;
}
}
</script>
</body>
</html>