線上服務(wù)咨詢
Article/文章
記錄成長(zhǎng)點(diǎn)滴 分享您我感悟
您當(dāng)前位置>首頁(yè) > 知識(shí) > 軟件開(kāi)發(fā)
微信小程序驗(yàn)證碼如何實(shí)現(xiàn)?(源代碼)
發(fā)表時(shí)間:2019-05-20 08:50:40
文章來(lái)源:沈陽(yáng)網(wǎng)站建設(shè)
標(biāo)簽:微信小程序驗(yàn)證碼 微信小程序驗(yàn)證碼如何實(shí)現(xiàn)
瀏覽次數(shù):0
本篇文章給大家?guī)?lái)的內(nèi)容是關(guān)于微信小程序驗(yàn)證碼如何實(shí)現(xiàn)?(源代碼),有一定的參考價(jià)值,有需要的朋友可以參考一下,希望對(duì)你有所幫助。
驗(yàn)證碼:
<input bindinput="makecodeInput" type="text"><view bindtap="getcode" class="makecode">{{code}}</view><button bindtap="login">登錄</button>
index.js
data: {code: "",makecode:"",},//獲取輸入驗(yàn)證碼makecodeInput:function(e){this.setData({makecode:e.detail.value})},// 登錄login: function() {if(this.data.makecode != this.data.code){wx.showToast({title: '驗(yàn)證碼不正確',icon: 'none',duration: 2000})}},//驗(yàn)證碼createCode() {var code;//首先默認(rèn)code為空字符串code = '';//設(shè)置長(zhǎng)度,這里看需求,我這里設(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軟件開(kāi)發(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)聽(tīng)頁(yè)面加載*/onLoad: function(options) {this.createCode();},getcode: function() {this.createCode();},
以上就是對(duì)微信小程序驗(yàn)證碼如何實(shí)現(xiàn)?(源代碼)的全部介紹,如果您想了解更多有關(guān)微信小程序開(kāi)發(fā)教程,請(qǐng)關(guān)注PHP中文網(wǎng)。
以上就是微信小程序驗(yàn)證碼如何實(shí)現(xiàn)?(源代碼)的詳細(xì)內(nèi)容,更多請(qǐng)關(guān)注沈陽(yáng)網(wǎng)站建設(shè)其它相關(guān)文章!
微信小程序驗(yàn)證碼,微信小程序驗(yàn)證碼如何實(shí)現(xiàn)