微信小程序獲取驗(yàn)證碼60秒倒計(jì)時(shí)功能
效果圖
index.wxml
<view class="Info"> <view class="Num"> <view>6位數(shù)字驗(yàn)證碼</view> <view class="verification_time"> <button bindtap='MosendSms' disabled='{{MoDisabled}}' class="Box_hid" style='color:{{MoColor}}' type="button">{{MoCodeMsg}}</button> </view> </view> <view class='verification'> <block wx:for="{{Length}}" wx:key="item"> <input class='frame' value="{{Showboxval.length>=index+1?Showboxval[index]:''}}" disabled catchtap='InputTap' /> </block> </view> <view class="error" wx:if="{{error}}">驗(yàn)證碼輸入錯(cuò)誤</view> <input name="password" password="{{true}}" class='ipt' maxlength="{{Length}}" focus="{{isFocus}}" bindinput="FocuInput" /> </view>
index.js
data: { code: "", //后端驗(yàn)證碼 Jurisdiction: true, //是否有權(quán)限 error: false, //錯(cuò)誤提示 Length: 6, //輸入框個(gè)數(shù) isFocus: true, //聚焦 Showboxval: "", //輸入的內(nèi)容 MoDisabled: false, //驗(yàn)證碼是否可點(diǎn)擊 MoCodeMsg: '獲取驗(yàn)證碼', //文案 MoMsgWait: 60, //時(shí)間秒 MoColor: 'rgba(40, 200, 122, 1)', //默認(rèn)驗(yàn)證碼字體顏色 },
/** * 生命周期函數(shù)--監(jiān)聽(tīng)頁(yè)面加載 正常第一次進(jìn)來(lái)先調(diào)用一次 */ onLoad(options) { this.MosendSms() // 60秒后重新獲取驗(yàn)證碼 },
// 60秒后驗(yàn)證碼 sendSbinms() { wx.showToast({ title: '短信驗(yàn)證碼發(fā)送成功,請(qǐng)注意查收', icon: 'none' }) this.setData({ MoCodeMsg: this.data.MoMsgWait + " s", MoColor: 'rgba(40, 200, 122, 1)', MoMsgWait: this.data.MoMsgWait - 1, MoDisabled: true }); let inter = setInterval(function () { this.setData({ MoCodeMsg: this.data.MoMsgWait + " s", MoColor: 'rgba(40, 200, 122, 1)', MoMsgWait: this.data.MoMsgWait - 1, MoDisabled: true }); if (this.data.MoMsgWait < 0) { clearInterval(inter) this.setData({ MoCodeMsg: "重新獲取", MoMsgWait: 60, MoDisabled: false, MoColor: 'rgba(40, 200, 122, 1)' }); } //注意后面的bind綁定,最關(guān)鍵。不然又是未定義,無(wú)法使用外圍的變量; }.bind(this), 1000); },
// 點(diǎn)擊獲取驗(yàn)證碼 MosendSms() { if (this.data.Jurisdiction) { this.sendSbinms() // 60秒后重新獲取驗(yàn)證碼 this.obtain(); //后端接口 獲取驗(yàn)證碼 } else { wx.showToast({ title: this.data.massage ? this.data.massage : '手機(jī)號(hào)未注冊(cè)', icon: 'error', duration: 3000 }) } },
obtain() { let params = { phone: this.data.rstProduct, type: 1 } appletValidateCode(params).then((res) => { this.setData({ code: res.data.data, }); }).catch((res) => {}) },
//驗(yàn)證碼輸入框 FocuInput(e) { let that = this; let inputValue = e.detail.value; that.setData({ Showboxval: inputValue, }) if (inputValue.length === 6) { if (inputValue == this.data.code) { this.setData({ error: false, }); } else { this.setData({ error: true, }); } } },
//驗(yàn)證碼輸入框點(diǎn)擊 InputTap() { let that = this; that.setData({ isFocus: true, }) },
index.wxss
.Info { padding: 138rpx 32rpx 0 32rpx; } .verification { display: flex; align-items: center; justify-content: space-between; margin-top: 30rpx; font-size: 32rpx; } .Num { display: flex; align-items: center; justify-content: space-between; color: rgba(0, 0, 0, 0.65); font-size: 30rpx; font-family: PingFang SC-Regular, PingFang SC; font-weight: 400; } .frame { width: 80rpx; height: 80rpx; border-radius: 2px; border: 2rpx solid #DEDEDE; display: flex; justify-content: center; align-items: center; text-align: center; font-size: 32rpx; font-family: PingFang SC-Medium, PingFang SC; font-weight: 500; color: rgba(0, 0, 0, 0.65); } .ipt { width: 0; height: 0; } .Box_hid { font-size: 30rpx; background: #fff !important; text-align: left; color: rgba(40, 200, 122, 1) !important; padding-right: 0 !important; font-family: PingFang SC-Regular, PingFang SC; font-weight: 400 !important; } .Box_hid::after { border: none; } .error { color: #F24236; margin-top: 8rpx; font-size: 28rpx; font-family: PingFang SC-Regular, PingFang SC; font-weight: 400; }
到此這篇關(guān)于微信小程序獲取驗(yàn)證碼60秒倒計(jì)時(shí)模板的文章就介紹到這了,更多相關(guān)微信小程序60秒倒計(jì)時(shí)內(nèi)容請(qǐng)搜索腳本之家以前的文章或繼續(xù)瀏覽下面的相關(guān)文章希望大家以后多多支持腳本之家!
相關(guān)文章
淺談JavaScript的計(jì)時(shí)器對(duì)象
下面小編就為大家?guī)?lái)一篇淺談JavaScript的計(jì)時(shí)器對(duì)象。小編覺(jué)得挺不錯(cuò)的,現(xiàn)在就分享給大家,也給大家做個(gè)參考。一起跟隨小編過(guò)來(lái)看看吧,祝大家游戲愉快哦2016-12-12非常不錯(cuò)的一個(gè)JS分頁(yè)效果代碼,值得研究
非常不錯(cuò)的一個(gè)JS分頁(yè)效果代碼,值得研究...2007-06-06JavaScript實(shí)現(xiàn)簡(jiǎn)單進(jìn)度條效果
這篇文章主要為大家詳細(xì)介紹了JavaScript實(shí)現(xiàn)簡(jiǎn)單進(jìn)度條效果,文中示例代碼介紹的非常詳細(xì),具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下2020-03-03bootstrapTable+ajax加載數(shù)據(jù) refresh更新數(shù)據(jù)
這篇文章主要為大家詳細(xì)介紹了bootstrapTable+ajax加載數(shù)據(jù),以及refresh更新數(shù)據(jù),具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下2018-08-08Google 爬蟲如何抓取 JavaScript 的內(nèi)容
我們測(cè)試了谷歌爬蟲是如何抓取 JavaScript,下面就是我們從中學(xué)習(xí)到的知識(shí),需要的朋友可以參考下2017-04-04js發(fā)送短信倒計(jì)時(shí)的簡(jiǎn)單實(shí)現(xiàn)方法
下面小編就為大家?guī)?lái)一篇js發(fā)送短信倒計(jì)時(shí)的簡(jiǎn)單實(shí)現(xiàn)方法。小編覺(jué)得挺不錯(cuò)的,現(xiàn)在就分享給大家,也給大家做個(gè)參考。一起跟隨小編過(guò)來(lái)看看吧2016-09-09Javascript 中文字符串處理額外注意事項(xiàng)
javascript文件中的字符常量與所在的js文件字符編碼密切相關(guān),如下一段代碼2009-11-11微信公眾號(hào)平臺(tái)接口開(kāi)發(fā) 菜單管理的實(shí)現(xiàn)
這篇文章主要介紹了微信公眾號(hào)平臺(tái)接口開(kāi)發(fā) 菜單管理的實(shí)現(xiàn),文中通過(guò)示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友可以參考下2019-08-08