js点击 密码输入框密码显示隐藏

时间:2023-03-08 23:24:31
js点击   密码输入框密码显示隐藏

很多密码框都有个眼睛标记,点击能显示密码。原理就是点击切换password为text等显示

下面上代码

 <!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title></title>
<style type="text/css">
.pass{
width:200px;
height: 20px;
}
</style>
<script>
window.onload=function(){
var btn=document.getElementById("btn");
var pass=document.getElementById("pass")
btn.onmousedown=function(){
pass.type="number"
};
btn.onmouseup=btn.onmouseout=function(){
pass.type="password"
}
}
</script>
</head>
<body>
<input type="password" name="" id="pass" value="123456" class="pass"/>
<input type="button" name="" id="btn" value="点击显示" />
</body>
</html>