原生js實(shí)現(xiàn)密碼輸入框值的顯示隱藏
本文實(shí)例為大家分享了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語法實(shí)現(xiàn),可對應(yīng)換成jquery語法進(jìn)行邏輯控制
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)文章
使用控制臺破解百小度一個(gè)月只準(zhǔn)改一次名字
這篇文章主要介紹了使用控制臺破解百小度一個(gè)月只準(zhǔn)改一次名字的方法和代碼,有需要的小伙伴可以參考下。2015-08-08
利用原生JS與jQuery實(shí)現(xiàn)數(shù)字線性變化的動(dòng)畫
最近在工作中遇到一個(gè)需要,需要將數(shù)字實(shí)現(xiàn)遞增的動(dòng)態(tài)顯示,從網(wǎng)上找了相關(guān)的資料發(fā)現(xiàn)利用原生JS與jQuery都可以實(shí)現(xiàn),suoyi8下面這篇文章主要給大家介紹了利用原生JS與jQuery實(shí)現(xiàn)數(shù)字線性變化動(dòng)畫的相關(guān)資料,需要的朋友可以參考下。2017-02-02
javascript html5移動(dòng)端輕松實(shí)現(xiàn)文件上傳
這篇文章主要為大家詳細(xì)介紹了javascript html5移動(dòng)端輕松實(shí)現(xiàn)文件上傳的相關(guān)資料,文中示例代碼介紹的非常詳細(xì),具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下2016-03-03
xmlplus組件設(shè)計(jì)系列之選項(xiàng)卡(Tabbar)(5)
xmlplus 是一個(gè)JavaScript框架,用于快速開發(fā)前后端項(xiàng)目。這篇文章主要介紹了xmlplus組件設(shè)計(jì)系列之選項(xiàng)卡,具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下2017-05-05
詳解使用JWT實(shí)現(xiàn)單點(diǎn)登錄(完全跨域方案)
這篇文章主要介紹了詳解使用JWT實(shí)現(xiàn)單點(diǎn)登錄(完全跨域方案),文中通過示例代碼介紹的非常詳細(xì),對大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來一起學(xué)習(xí)學(xué)習(xí)吧2019-08-08
簡單時(shí)間提示DEMO從0開始一直進(jìn)行計(jì)時(shí)
點(diǎn)擊按鈕輸入框會從0開始一直進(jìn)行計(jì)時(shí),具體的實(shí)現(xiàn)示例如下,感興趣的朋友可以嘗試操作下哦2013-11-11

