1. 程式人生 > 其它 >短視訊商城系統,輸入密碼時點選可隱藏或顯示密碼內容

短視訊商城系統,輸入密碼時點選可隱藏或顯示密碼內容

短視訊商城系統,輸入密碼時點選可隱藏或顯示密碼內容實現的相關程式碼

<!DOCTYPE html>
<html>
    <head>
        <meta charset="UTF-8">
        <meta name="viewport" content="width=device-width,initial-scale=1.0">
        <meta http-equiv="X-UA-Compatible" content="ie=edge">
        <title>Document</title>
        <style>
            .box {
                width: 400px;
                border-bottom: 1px solid #ccc;
                margin: 100px auto;
                position: relative;
            }
            .box input {
                width: 370px;
                height: 30px;
                border: 0;/*取消邊框*/
                outline: none; /*取消選中時出來的文字框邊框*/
            }
            .box img {
                position: absolute;
                width: 43px;
                top: -10px;
                right: -1px;
            }
        </style>
    </head>
    <body>
        <div class="box">
            <label for="">
                <img src="b.png" alt="" id="eye">
            </label>
            <input type="password" id="pwd">
        </div>
        <script>
            //獲取元素
            var eye = document.getElementById('eye');
            var pwd = document.getElementById('pwd');
            //註冊事件
            var flag = 0;
            eye.onclick = function() {
                if(flag==0) {
                    pwd.type = 'text';
                    eye.src = 'a.png';
                    flag = 1;
                }
                else{
                    pwd.type = 'password';
                    eye.src = 'b.png';
                    flag = 0;
                }
            }
        </script>
    </body>
</html> 

​       

以上就是 短視訊商城系統,輸入密碼時點選可隱藏或顯示密碼內容實現的相關程式碼,更多內容歡迎關注之後的文章