您的位置:首页 > Web前端 > JavaScript

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

2015-12-29 15:21 543 查看
很多密码框都有个眼睛标记,点击能显示密码。原理就是点击切换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>
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: