效果图呈上
点击右边图(图随便加的)显示密码
再点击右边图,来回隐藏显示
代码
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
<style>
div{
background-color: antiquewhite;
width: 500px;
height: 50px;
position: relative;
}
.mm {
width: 500px;
height: 50px;
border: 1px solid transparent;
border-bottom: 1px solid grey;
outline: none;
}
img {
width: 50px;
position: absolute;
right: 10px;
}
</style>
</head>
<body>
<div>
<img src="../H5C3项目/第二周项目 天猫国际———登录页/登录页/img/上下.png" alt="">
<input type="password" class="mm">
</div>
<script>
let aniu=document.querySelector('img')
let yc=document.querySelector('input')
let d=0
aniu.onclick=function(){
if(d==0){
yc.type="text"
d=1
aniu.src="../H5C3项目/第二周项目 天猫国际———登录页/登录页/img/手机.png"
}
else{
yc.type="password"
d=0
aniu.src="../H5C3项目/第二周项目 天猫国际———登录页/登录页/img/上下.png"
}
}
</script>
</body>
</html>