大佬们,我点击密码框右侧 小眼睛,但是没反应,请问怎么回事?
<style>
#pwd{width:200px;height:30px;background:url('eye开.png') no-repeat right ;background-size: contain;}
</style>
</head>
<body>
密码: <input id="pwd" type="password" placeholder="请输入密码" >
<script>
var pwd=document.getElementById("pwd")
var img=document.getElementById("pwd").style.backgroundImage
img.onclick=function(){
if(pwd.type == "password"){
pwd.type = 'text'
img.src = 'eye闭.png'
}else{
pwd.type = 'password'
img.src = 'eye开.png'
}
}
</script>