仿京东登录显示隐藏密码

仿京东登录显示隐藏密码
D:\开发\Vue项目\Vue2学习\html练习\仿京东显示隐藏密码.html
<!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>仿京东登录显示隐藏密码</title>

    <style>
        .box {
            position: relative;
            width: 400px;
            margin: 100px auto;
            border-bottom: 1px solid #ccc;
        }

        .box input {
            width: 370px;
            height: 30px;
            border: 0;
            outline: none;
        }
        .box img {
            position: absolute;
            /* border: 1px solid; */
            width: 20px;
            top: 5px;
            right: 0%;
        }
    </style>
</head>
<body>
    <div class="box">
        <label for="">
            <img src="../images/闭眼睛.png" alt="" id="eye">
        </label>
        <input type="password" name="" id="pwd"></input>
    </div>


    <script>
        //1、获取元素
        var eye = document.getElementById('eye');
        var pwd = document.getElementById('pwd');
        //2、注册事件,处理程序
        var flag = 0;
        eye.onclick = function() {
            //点击一次,flag 一定要变化
            if (flag == 0) {
                pwd.type = "text";
                this.src = '../images/眼睛.png'
                flag = 1;
            } else {
                pwd.type = "password";
                this.src = '../images/闭眼睛.png'
                flag = 0;
            }            
        }

    </script>
</body>
</html>
图片文件
D:\开发\Vue项目\Vue2学习\images\眼睛.png
D:\开发\Vue项目\Vue2学习\images\闭眼睛.png
闭眼睛 眼睛
posted @ 2023-07-01 12:42  九秒钟的鱼  阅读(22)  评论(0编辑  收藏  举报