样式
.box {
position: relative;
width: 400px;
border-bottom: 1px solid red;
margin: 100px auto;
}
input {
width: 370px;
height: 30px;
border: 0;
outline: none;
}
.box img {
position: absolute;
right: 2px;
top: 3px;
width: 20px;
}
结构
<div class="box">
<label for="">
<img src="https://www.dataojocloud.com/dataeye/v1/data/image/get?imageid=617a5596fd73380b818dc300" id="eye">
</label>
<input type="password" id="pwd">
</div>
JS
var eye = document.getElementById('eye');
var pwd = document.getElementById('pwd');
var flag = 0;
eye.onclick = function ()
{
if (flag == 0)
{
pwd.type = 'text';
eye.src = 'https://www.dataojocloud.com/dataeye/v1/data/image/get?imageid=617a5596fd73380b818dc300';
flag = 1;
} else
{
eye.src = 'https://www.dataojocloud.com/dataeye/v1/data/image/get?imageid=617a559d2ee1bd5a04779569';
pwd.type = 'password';
flag = 0;
}
}