显示和隐藏密码

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>
<body>
    <input type="password" id="password" />
    <button id="show">显示/隐藏密码</button>
</body>
<script>
    {
        let show = document.querySelector('#show');
        let password = document.querySelector('#password')
        show.onclick = () => {
            if(password.getAttribute('type') !== 'text'){
                password.setAttribute('type','text')
            }else{
                password.setAttribute('type','password')
            }
        }
        
    }
</script>
</html>
posted @ 2020-09-16 13:24  东京樱花的哭泣灬  阅读(92)  评论(0)    收藏  举报