原生js實現(xiàn)密碼輸入框值的顯示隱藏
更新時間:2017年07月17日 10:42:47 作者:starkfang
這篇文章主要為大家詳細介紹了原生js實現(xiàn)密碼輸入框值的顯示隱藏,文中示例代碼介紹的非常詳細,具有一定的參考價值,感興趣的小伙伴們可以參考一下
本文實例為大家分享了js顯示隱藏密碼輸入框值的具體代碼,供大家參考,具體內(nèi)容如下
直接貼上代碼
<!DOCTYPE html>
<html>
<head>
<title>password intput demo</title>
</head>
<style type="text/css">
body{
margin:0px;
background-color: white;
font-family: 'PT Sans', Helvetica, Arial, sans-serif;
text-align: center;
color: #A6A6A6;
}
/*輸入框樣式,去掉背景陰影模仿原生應(yīng)用的輸入框*/
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>
<body>
<div id="page_container">
<!--密碼輸入框-->
<div class="input_block">
<img id="demo_img" onclick="hideShowPsw()" src="visible.png">
<input type="password" id="demo_input" placeholder="Password"/>
</div>
<button onclick="">Login</button>
</div>
<script type="text/javascript">
// 這里使用最原始的js語法實現(xiàn),可對應(yīng)換成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 = "invisible.png";
}else {
demoInput.type = "password";
demo_img.src = "visible.png";
}
}
</script>
</body>
</html>
附上圖片:


以上就是本文的全部內(nèi)容,希望對大家的學(xué)習(xí)有所幫助,也希望大家多多支持腳本之家。
相關(guān)文章
利用原生JS與jQuery實現(xiàn)數(shù)字線性變化的動畫
最近在工作中遇到一個需要,需要將數(shù)字實現(xiàn)遞增的動態(tài)顯示,從網(wǎng)上找了相關(guān)的資料發(fā)現(xiàn)利用原生JS與jQuery都可以實現(xiàn),suoyi8下面這篇文章主要給大家介紹了利用原生JS與jQuery實現(xiàn)數(shù)字線性變化動畫的相關(guān)資料,需要的朋友可以參考下。2017-02-02
javascript html5移動端輕松實現(xiàn)文件上傳
這篇文章主要為大家詳細介紹了javascript html5移動端輕松實現(xiàn)文件上傳的相關(guān)資料,文中示例代碼介紹的非常詳細,具有一定的參考價值,感興趣的小伙伴們可以參考一下2016-03-03
xmlplus組件設(shè)計系列之選項卡(Tabbar)(5)
xmlplus 是一個JavaScript框架,用于快速開發(fā)前后端項目。這篇文章主要介紹了xmlplus組件設(shè)計系列之選項卡,具有一定的參考價值,感興趣的小伙伴們可以參考一下2017-05-05

