<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title></title>
<style type="text/css">
.box{
width: 400px;
border-bottom: 1px solid #FF0000;
margin: 100px auto;
position: relative;
}
.box input{
width: 370px;
height: 30px;
border:0 ;
outline: none;
}
label img{
width: 24px;
height: 24px;
position: absolute;
left: 380px;
}
</style>
</head>
<body>
<div class="box">
<label for=""><img src="img/yanjing.png" id="eye"></label>
<input type="password" id="psw" />
</div>
<script type="text/javascript">
var eye = document.getElementById('eye');//获取元素eye
var psw = document.getElementById('psw');//获取元素psw
var flag = 0;
eye.onclick =function(){
if(flag == 0 ){
psw.type = 'text';
eye.src ='img/yanjing.png';
flag =1;
}else{
psw.type = 'password';
eye.src ='img/biyan.png';
flag = 0 ;
}
}
</script>
</body>
</html>
js实现密码的显示和隐藏
最新推荐文章于 2024-04-08 21:28:38 发布