zoukankan      html  css  js  c++  java
  • 点击图片显示或隐藏密码案例

    <!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;
                 400px;
                border-bottom: 1px solid #ccc;
                margin: 100px auto;
            }
            
            .box input {
                border: 0;
                outline: none;
                 370px;
                height: 30px;
            }
            
            .box img {
                position: absolute;
                top: 2px;
                right: 2px;
                 24px;
            }
        </style>
    </head>

    <body>
        <div class="box">
            <label for="">
                <img src="images/close.png" alt="" id="eye">
            </label>
            <input type="password" id="pwd">
        </div>


        <script>
            // 1 获取元素 
            var eye = document.getElementById('eye');
            var pwd = document.getElementById('pwd');
            // 切换显示隐藏
            var flag = 0;
            //  2 注册事件 绑定程序
            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>
  • 相关阅读:
    MVC的布局页,视图布局页和分布页的使用
    C#程序的编译过程
    页面跳转到Area区域连接
    c#静态变量和非静态变量的区别
    C#设计模式:适配器模式(Adapter Pattern)
    依赖注入
    打印随机数到字符串中
    printf/scanf格式
    用fread和fwrite实现文件复制操作
    用fseek和ftell获取文件的大小
  • 原文地址:https://www.cnblogs.com/ericblog1992/p/13050632.html
Copyright © 2011-2022 走看看