基于vue 實現(xiàn)表單中password輸入的顯示與隱藏功能
實現(xiàn)效果:
點擊 “眼睛” 的時候顯示與隱藏
代碼:
<!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輸入密碼顯示與隱藏實現(xiàn):
效果(點擊顯示與隱藏進行切換):
代碼:
<!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>
總結(jié)
以上所述是小編給大家介紹的基于vue 實現(xiàn)表單中password輸入的顯示與隱藏功能,希望對大家有所幫助,如果大家有任何疑問請給我留言,小編會及時回復大家的。在此也非常感謝大家對腳本之家網(wǎng)站的支持!
如果你覺得本文對你有幫助,歡迎轉(zhuǎn)載,煩請注明出處,謝謝!
相關(guān)文章
一起寫一個即插即用的Vue Loading插件實現(xiàn)
這篇文章主要介紹了一起寫一個即插即用的Vue Loading插件實現(xiàn),文中通過示例代碼介紹的非常詳細,對大家的學習或者工作具有一定的參考學習價值,需要的朋友們下面隨著小編來一起學習學習吧2019-10-10在vue中路由使用this.$router.go(-1)返回兩次問題
這篇文章主要介紹了在vue中路由使用this.$router.go(-1)返回兩次問題,具有很好的參考價值,希望對大家有所幫助,如有錯誤或未考慮完全的地方,望不吝賜教2023-12-12在Vue中進行數(shù)據(jù)分頁的實現(xiàn)方法
在前端開發(fā)中,數(shù)據(jù)分頁是一個常見的需求,特別是當處理大量數(shù)據(jù)時,Vue作為一款流行的JavaScript框架,提供了強大的工具和生態(tài)系統(tǒng)來實現(xiàn)數(shù)據(jù)分頁,本文將介紹如何在Vue中進行數(shù)據(jù)分頁,以及如何設(shè)計一個通用的分頁組件,需要的朋友可以參考下2023-10-10vue中計算屬性computed和普通屬性method的區(qū)別小結(jié)
Vue.js中Computed和Methods是兩種常用的數(shù)據(jù)處理方式,本文主要介紹了vue中計算屬性computed和普通屬性method的區(qū)別小結(jié),具有一定的參考價值,感興趣的可以了解一下2024-06-06