JavaScrip 仿京东密码显示案例
【摘要】
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<me...
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
<style>
.box {
position: relative;
width: 400px;
border-bottom: 1px solid #ccc;
margin: 100px auto;
}
.box input {
width: 370px;
height: 30px;
border: 0px;
outline: none;
}
.box img {
position: absolute;
width: 24px;
top: 2px;
right: 2px;
}
</style>
</head>
<body>
<div class="box">
<label for="">
<img src="./images/close.png" alt="" id="eye">
</label>
<input type="password" name="" id="pwd">
</div>
<script>
// 1. 获取元素
var eye = document.getElementById('eye');
var pwd = document.getElementById('pwd');
// 2. 绑定事件 + 函数
var flag = 0 ;
eye.onclick = function () {
if ( flag == 0) {
pwd.type = 'text' ;
eye.src = 'images/open.png' ;
flag = 1;
} else {
pwd.type = 'password' ;
eye.src = 'images/close.png' ;
flag = 0 ;
}
}
</script>
</body>
</html>
文章来源: blog.csdn.net,作者:花花叔叔,版权归原作者所有,如需转载,请联系作者。
原文链接:blog.csdn.net/qq_52077949/article/details/120167921
【版权声明】本文为华为云社区用户转载文章,如果您发现本社区中有涉嫌抄袭的内容,欢迎发送邮件进行举报,并提供相关证据,一经查实,本社区将立刻删除涉嫌侵权内容,举报邮箱:
cloudbbs@huaweicloud.com
- 点赞
- 收藏
- 关注作者
作者其他文章
评论(0)