登录页面的密码的显示与隐藏

原理就是点击的时候把密码的输入框的类型从password切换到text,再次点击把text切换成password,懒的话可以直接声明按钮点击,美观点的话可以去阿里icon官网上选几个使用

效果

在这里插入图片描述
在这里插入图片描述
选择喜欢的icon以png的形式下载到本地放在项目中引用即可

丰富的icon资源:https://www.iconfont.cn/

在这里插入图片描述
在这里插入图片描述

代码

<%--
  Created by IntelliJ IDEA.
  User: wx_weiyihe
  Date: 2021/8/30
  Time: 14:00
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<script src="https://code.jquery.com/jquery-3.1.1.min.js"></script>
<html>
<head>
    <title>Title</title>
</head>

<style>
    *{
        margin: 0;
        padding: 0;
        box-sizing: border-box;
    }
    body{
        height: 100vh;
        display: flex;
        align-items: center;
        justify-content: center;
    }
    .kuang{
        position: relative;
        width: 380px;
        height: 60px;
        border-radius: 5px;
        /*  background-color: rgba(204, 197, 197,.5); */
        box-shadow: inset 5px 5px 10px rgba(204, 197, 197,.5),
        inset -5px -5px 8px rgba(204, 197, 197,.5);
    }
    .kuang input{
        position: absolute;
        top: 0;
        left: 20px;
        height: 100%;
        width: 300px;
        font-size: 18px;
        outline: none;
        border: none;
        background-color:transparent;
    }
    .kuang input::placeholder{
        color: rgba(68, 67, 67,.8);
    }
    .conceal{
        position: absolute;
        top: 15px;
        right: 15px;
        width: 30px;
        height: 30px;
        background-image: url(../image/open.png);
        background-size: 100% 100%;
        cursor: pointer;
    }
    .conceal.yincang{
        background-image: url(../image/close.png);
        background-size: 100% 100%;
    }
</style>

<body>
<div class="kuang">
    <input type="password" placeholder=" 请输入密码......" id='password' >
    <div class="conceal" id='conceal'></div>
</div>
<script>
    var password = document.getElementById('password');
    var anniu = document.getElementById('conceal');
    anniu.addEventListener('click',function(){
        if(password.type==='password')
        {
            password.setAttribute('type','text');
            anniu.classList.add('yincang');
        }else{
            password.setAttribute('type','password');
            anniu.classList.remove('yincang');
        }
    })
</script>
</body>



</html>

icon路径

在这里插入图片描述

引用

  background-image: url(../image/open.png);
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

小花皮猪

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值