input密码框点击眼睛显示和隐藏

俩张图片表示显示和隐藏,要是想改样式的话直接修改css就可以,根据自己样式来

很简单获取到相对应对密码框,

初始化是隐藏调用方法hideShowPsw进行判断,判断密码框的type == “password”是隐藏 变成type==“text”图片在变一下就好了 


<!DOCTYPE html>

<html>
<head>
<meta charset="UTF-8">
<title></title>
<link rel="stylesheet" href="css/base.css" />
<style>
body{  
   margin:0px;    
   background-color: white;   
   font-family: 'PT Sans', Helvetica, Arial, sans-serif;    
   text-align: center;    
   color: #A6A6A6;    
}  
/*输入框样式,去掉背景阴影模仿原生应用的输入框*/  
input{  
width: 100%;    
height: 50px;    
border:none;    
padding-left:3px;    
font-size: 18px;    
}  
input:focus {    
   outline: none;    
}  
/*显示隐藏密码图片*/  
img{  
width: 40px;  
height: 25px;  
position: absolute;    
right: 0px;   
margin: 15px;    
}  
/*登录按钮*/  
button{    
   width: 200px;    
   height: 50px;    
   margin-top: 25px;    
   background: #1E90FF;    
   border-radius: 10px;    
   border:none;  
   font-size: 18px;  
   font-weight: 700;    
   color: #fff;  
}  
button:hover {  
background: #79A84B;    
outline: 0;  
}  
/*输入框底部半透明横线*/  
.input_block {  
   border-bottom: 1px solid rgba(0,0,0,.1);  
}  
/*container*/  
#page_container{  
   margin: 50px;  
}  
</style>
</head>
<body>
<!--<div id="page_container">-->  
   <!--暗文密码输入框-->  
   <!--<div class="input_block" id="psw_invisible">  
       <img id="visible" οnclick="showPsw()" src="img/hide.png">  
       <input type="password" id="input_invisible" placeholder="Password"/>  
   </div>  -->
   <!--明文密码输入框-->  
   <!--<div class="input_block" id="psw_visible" style="display: none;">  
       <img id="invisible" οnclick="hidePsw()" src="img/show.png">  
       <input type="text" id="input_visible" placeholder="Password"/>  
   </div>  
 
   <button οnclick="">Login</button>  
</div>  -->

<div id="page_container">  
   <!--密码输入框-->  
   <div class="input_block">  
       <img id="demo_img" οnclick="hideShowPsw()" src="img/hide.png">  
       <input type="password" id="demo_input" placeholder="Password"/>  
   </div>  
 
   <button οnclick="">Login</button>  
</div>  
</body>

<script type="text/javascript">  
   // 这里使用最原始的js语法实现,可对应换成jquery语法进行逻辑控制  
//    var visible=document.getElementById('psw_visible');//text block  
//    var invisible=document.getElementById('psw_invisible');//password block  
//    var inputVisible = document.getElementById('input_visible');  
//    var inputInVisible = document.getElementById('input_invisible');  
   //隐藏text block,显示password block  
//    function showPsw(){  
//        var val = inputInVisible.value;//将password的值传给text  
//        inputVisible.value = val;  
//        invisible.style.display = "none";    
//        visible.style.display = "";    
//    }  
   //隐藏password,显示text    
//    function hidePsw(){  
//        var val=inputVisible.value;//将text的值传给password    
//        inputInVisible.value = val;   
//        invisible.style.display = "";    
//        visible.style.display = "none";    
//    }  


// 这里使用最原始的js语法实现,可对应换成jquery语法进行逻辑控制  
   var demoImg = document.getElementById("demo_img");  
   var demoInput = document.getElementById("demo_input");  
   //隐藏text block,显示password block  
   function hideShowPsw(){  
       if (demoInput.type == "password") {  
           demoInput.type = "text";  
           demo_img.src = "img/show.png";  
       }else {  
           demoInput.type = "password";  
           demo_img.src = "img/hide.png";  
       }  
   }  
   
   
</script>
</html>
  • 4
    点赞
  • 16
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值