這篇文章主要介紹js怎么實現input密碼框顯示/隱藏功能,文中介紹的非常詳細,具有一定的參考價值,感興趣的小伙伴們一定要看完!
1、js屬于一種解釋性腳本語言;2、在絕大多數瀏覽器的支持下,js可以在多種平臺下運行,擁有著跨平臺特性;3、js屬于一種弱類型腳本語言,對使用的數據類型未做出嚴格的要求,能夠進行類型轉換,簡單又容易上手;4、js語言安全性高,只能通過瀏覽器實現信息瀏覽或動態交互,從而有效地防止數據的丟失;5、基于對象的腳本語言,js不僅可以創建對象,也能使用現有的對象。
JavaScript實現input密碼框顯示/隱藏的功能,供大家參考,具體內容如下

實現代碼:
<!DOCTYPE html>
<html>
<head>
<title></title>
<style type="text/css">
.password{
position: relative;
width: 280px;
height: 60px;
}
.password,.n-txtCss{
display: flex;
align-items: center;
}
.password .fa{
position: absolute;
right: 10px;
top:15px;
font-size: 20px;
cursor: pointer;
}
.fa-eye-slash{
margin-top: 6px;
margin-left: 7px;
width: 24px;
height: 20px;
background-image: url(./vivo_img/login/eye-password.png);
background-repeat: no-repeat;
background-size: 24px 17px;
}
.fa-eye{
margin-top: 6px;
width: 24px;
margin-left: 7px;
height: 20px;
background-image: url(./vivo_img/login/eye-password-active.png);
background-repeat: no-repeat;
background-size: 24px 17px;
}
</style>
<script type="text/javascript" src="js/jquery-1.12.4.min.js"></script>
</head>
<body>
<dd class="password">
<input type="password" name="" placeholder="設置密碼:8-16位字母和數字" maxlength="16" >
<i class="fa fa-eye-slash"></i>
</dd>
<script type="text/javascript">
$(".password").on("click", ".fa-eye-slash", function () {
$(this).removeClass("fa-eye-slash").addClass("fa-eye");
$(this).prev().attr("type", "text");
});
$(".password").on("click", ".fa-eye", function () {
$(this).removeClass("fa-eye").addClass("fa-eye-slash");
$(this).prev().attr("type", "password");
});
</script>
</body>
</html>以上是“js怎么實現input密碼框顯示/隱藏功能”這篇文章的所有內容,感謝各位的閱讀!希望分享的內容對大家有幫助,更多相關知識,歡迎關注億速云行業資訊頻道!
免責聲明:本站發布的內容(圖片、視頻和文字)以原創、轉載和分享為主,文章觀點不代表本網站立場,如果涉及侵權請聯系站長郵箱:is@yisu.com進行舉報,并提供相關證據,一經查實,將立刻刪除涉嫌侵權內容。