JS實現(xiàn)登錄頁密碼的顯示和隱藏功能
在登錄頁經(jīng)常會用到通過點擊文本框的類似小眼睛圖片來實現(xiàn)隱藏顯示密碼的功能,其實實現(xiàn)原理很簡單,通過點擊事件來改變input的type類型,具體過程看代碼:
在沒給大家分享實現(xiàn)代碼之前,先給大家展示下效果圖:


<ul class="form-area">
<li>
<div class="item-content">
<div class="item-input">
<input type="text" name="accountName" autofocus required="required" placeholder="請輸入用戶名">
</div>
</div>
</li>
<li>
<div class="item-content">
<div class="item-input">
<input type="password" name="password" id="password" required="required" placeholder="請輸入密碼">
</div>
</div>
</li>
<li>
<span style="position:absolute;right: 20px;top: -38px">
<img id="showText" onclick="hideShowPsw()">
</span>
</li>
</ul>
<script type="text/javascript">
//獲取input框內(nèi)的切換圖片id和input文本框的id
var demoImg = document.getElementById("showText");
var demoInput = document.getElementById("password");
function hideShowPsw() {
if (demoInput.type == "password") {
demoInput.type = "text";
demoImg.src ="../Images/showPasswd.png";
} else {
demoInput.type = "password";
demoImg.src = "../Images/hidePasswd.png";
}
}
</script>
總結(jié)
以上所述是小編給大家介紹的JS實現(xiàn)登錄頁密碼的顯示和隱藏,希望對大家有所幫助,如果大家有任何疑問請給我留言,小編會及時回復(fù)大家的。在此也非常感謝大家對腳本之家網(wǎng)站的支持!
相關(guān)文章
淺談通過JS攔截 pushState和replaceState事件
下面小編就為大家?guī)硪黄獪\談通過JS攔截 pushState和replaceState事件。小編覺得挺不錯的,現(xiàn)在就分享給大家,也給大家做個參考。一起跟隨小編過來看看吧2017-07-07
在JavaScript中調(diào)用OpenAI?API的詳細步驟
在?JavaScript?中調(diào)用?OpenAI?API?也非常簡單,下面我將結(jié)合具體代碼示例以及使用場景,詳細講解如何使用?JavaScript?調(diào)用?OpenAI?API,需要的朋友可以參考下2025-04-04
Javascript Function對象擴展之延時執(zhí)行函數(shù)
這篇文章主要介紹 在js里面怎么延時執(zhí)行一個函數(shù)?2010-07-07
用javascript連接access數(shù)據(jù)庫的方法
用javascript連接access數(shù)據(jù)庫的方法...2006-11-11
第九篇Bootstrap導(dǎo)航菜單創(chuàng)建步驟詳解
這篇文章主要介紹了Bootstrap導(dǎo)航菜單創(chuàng)建步驟詳解的相關(guān)資料,非常不錯,具有參考借鑒價值,需要的朋友可以參考下2016-06-06

