基于vue 實現表單中password輸入的顯示與隱藏功能
更新時間:2019年07月19日 16:47:54 作者:rachelch
這篇文章主要介紹了vue 實現表單中password輸入的顯示與隱藏功能 ,本文給大家介紹的非常詳細,具有一定的參考借鑒價值,需要的朋友可以參考下
實現效果:

點擊 “眼睛” 的時候顯示與隱藏

代碼:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<link href="css/bootstrap.min.css" rel="external nofollow" rel="stylesheet">
<script src="js/vue.js"></script>
<title>Title</title>
<style>
#main{
text-align: center;
margin-top:60px;
}
input[type=text],input[type=password]{
width:260px;
height:28px;
display: inline-block;
}
span{
margin-left:-30px;
cursor: pointer;
}
input[type=checkbox]{
cursor: pointer;
opacity: 0;
margin-left:-18px;
display: inline-block;
}
</style>
</head>
<body>
<div id="main">
<input type="text" class="form-control" v-model="msg" v-if="checked">
<input type="password" class="form-control" v-model="msg" v-else>
<span class="glyphicon glyphicon-eye-open"></span>
<input type="checkbox" v-model="checked">
</div>
<script>
new Vue({
el:"#main",
data:{
msg:"",
checked:false
},
methods:{
}
});
</script>
<script src="js/jquery.min.js"></script>
<script src="js/bootstrap.min.js"></script>
</body>
</html>
=====================================
登錄頁面input輸入密碼顯示與隱藏實現:
效果(點擊顯示與隱藏進行切換):


代碼:
<!doctype html>
<html>
<head>
<meta charset="UTF-8">
<title></title>
<meta name="viewport" content="width=device-width,initial-scale=1,minimum-scale=1,maximum-scale=1,user-scalable=no" />
<script src="js/vue.js"></script>
<script src="js/vue-resource.js"></script>
<style>
body{
background:white;
}
.main{
padding-top:50px;width:95%;margin:0 auto;
}
.account{
border-bottom:1px solid #dfdfdf;padding-top:28px;
}
.account input{
border:none;font-size:14px;margin-bottom:5px;width:91.5%;height:44px;
}
.account i{
width:14px;
height:14px;
line-height:14px;
font-size:18px;
display:inline-block;
color:white;
background:#cdcdcd;
border-radius:50%;
text-align:center;
font-style:normal;
}
.account .psd{
width:81.6%;
}
.account span{
color:#bfbfbf;float:right;line-height:40px;
}
</style>
</head>
<body>
<div id="login">
<div class="main">
<div class="account">
<input type="password" placeholder="密碼" class="psd" v-model="psd" v-if="ifDisplay"/>
<input type="text" placeholder="密碼" class="psd" v-model="psd" v-else/>
<i v-show="psd" @click="clearPassword()">×</i>
<span v-show="ifDisplay" @click="ifDisplay=!ifDisplay">隱藏</span>
<span v-show="!ifDisplay" @click="ifDisplay=!ifDisplay">顯示</span>
</div>
</div>
</div>
<script type="text/javascript">
var vm=new Vue({
el:'#login',
data:{
username:'',
psd:'',
ifDisplay:false,
},
methods:{
clearPassword:function(){
this.psd='';
},
}
})
</script>
</body>
</html>
總結
以上所述是小編給大家介紹的基于vue 實現表單中password輸入的顯示與隱藏功能,希望對大家有所幫助,如果大家有任何疑問請給我留言,小編會及時回復大家的。在此也非常感謝大家對腳本之家網站的支持!
如果你覺得本文對你有幫助,歡迎轉載,煩請注明出處,謝謝!
相關文章
基于uniapp+vue3自定義增強版table表格組件「兼容H5+小程序+App端」
uv3-table:一款基于uniapp+vue3跨端自定義手機端增強版表格組件,支持固定表頭/列、邊框、斑馬紋、單選/多選,自定義表頭/表體插槽、左右固定列陰影高亮顯示,支持編譯兼容H5+小程序端+App端,H5+小程序+App端,多端運行一致2024-05-05
vue jsx 使用指南及vue.js 使用jsx語法的方法
這篇文章主要介紹了vue jsx 使用指南及vue.js 使用jsx語法的方法,非常不錯,具有參考借鑒價值,需要的朋友可以參考下2017-11-11
vue.js默認路由不加載linkActiveClass問題的解決方法
這篇文章主要給大家介紹了關于vue.js默認路由不加載linkActiveClass問題的解決方法,文中通過示例代碼介紹的非常詳細,對大家的學習或者工作具有一定的參考學習價值,需要的朋友們下面來一起看看吧。2017-12-12

