線上服務(wù)咨詢
Article/文章
記錄成長點滴 分享您我感悟
微信小程序驗證碼如何實現(xiàn)?(源代碼)
發(fā)表時間:2019-05-20 08:50:40
文章來源:沈陽網(wǎng)站建設(shè)
標(biāo)簽:微信小程序驗證碼 微信小程序驗證碼如何實現(xiàn)
瀏覽次數(shù):0
本篇文章給大家?guī)淼膬?nèi)容是關(guān)于微信小程序驗證碼如何實現(xiàn)?(源代碼),有一定的參考價值,有需要的朋友可以參考一下,希望對你有所幫助。
驗證碼:
<input bindinput="makecodeInput" type="text"><view bindtap="getcode" class="makecode">{{code}}</view><button bindtap="login">登錄</button>
index.js
data: {code: "",makecode:"",},//獲取輸入驗證碼makecodeInput:function(e){this.setData({makecode:e.detail.value})},// 登錄login: function() {if(this.data.makecode != this.data.code){wx.showToast({title: '驗證碼不正確',icon: 'none',duration: 2000})}},//驗證碼createCode() {var code;//首先默認(rèn)code為空字符串code = '';//設(shè)置長度,這里看需求,我這里設(shè)置了4var codeLength = 4;//設(shè)置隨機(jī)字符var random = new Array(0, 1, 2, 3, 4, 5, 6, 7, 8, 9);//循環(huán)codeLength 我設(shè)置的4就app軟件開發(fā)是循環(huán)4次for (var i = 0; i < codeLength; i++) {//設(shè)置隨機(jī)數(shù)范圍,這設(shè)置為0 ~ 10var index = Math.floor(Math.random() * 10);//字符串拼接 將每次隨機(jī)的字符 進(jìn)行拼接code += random[index];}//將拼接好的字符串賦值給展示的codethis.setData({code: code})},/*** 生命周期函數(shù)--監(jiān)聽頁面加載*/onLoad: function(options) {this.createCode();},getcode: function() {this.createCode();},
以上就是對微信小程序驗證碼如何實現(xiàn)?(源代碼)的全部介紹,如果您想了解更多有關(guān)微信小程序開發(fā)教程,請關(guān)注PHP中文網(wǎng)。
以上就是微信小程序驗證碼如何實現(xiàn)?(源代碼)的詳細(xì)內(nèi)容,更多請關(guān)注沈陽網(wǎng)站建設(shè)其它相關(guān)文章!
微信小程序驗證碼,微信小程序驗證碼如何實現(xiàn)