[notice-block]
<!DOCTYPE html>
<head>
<meta charset="utf-8">
<title></title>
<style type="text/css">
.box{
width: 400px;
border-bottom: 1px solid #CCCCCC ;
margin: 100px auto;
position: relative;
}
.box input{
width: 370px;
height: 30px;
border: 0;
outline: none;
}
label img{
width: 24px;
position: absolute;/*绝对定位*/
top: 2px;
right: 2px;
}
</style>
</head>
<body>
<div class="box">
<label for="">
<img src="./close.png" alt="" id="eye">
</label>
<input type="password" name="" id="pwd"/>
</div>
<script type="text/javascript">
let flag=0;
var eye=document.getElementById('eye');
var pwd=document.getElementById('pwd');
eye.onclick=function(){
if(flag==false){
pwd.type='text';
eye.src='./open.png';
flag=!flag;
}else{
pwd.type='password';
eye.src='./close.png';
flag=!flag;
}
}
</script>
</body>
[/notice-block]