小程序?qū)崿F(xiàn)簡(jiǎn)單驗(yàn)證碼倒計(jì)時(shí)
本篇文章主要講關(guān)于小程序驗(yàn)證碼倒計(jì)時(shí)的功能實(shí)現(xiàn),供大家參考,具體內(nèi)容如下


首先是wxml部分
<form bindsubmit="regist">
? ? <view class="vip-title">驗(yàn)證碼</view>
? ? ? <input type="text" name="verifyCode" placeholder="驗(yàn)證碼" value="{{verifyCode}}" style="width:310rpx" />
? ? ? <button class="captcha" bindtap="captcha" disabled="{{captchaDisabled}}" plain="true" disabled-class="disabled">{{captchaLabel}}</button>
? ? </view>
?</form>樣式部分:
/*提交按鈕*/
form button {
? ? margin: 30rpx;
? ? background: #09f;
? ? color: white;
}
/*文本框容器*/
.input-container {
? ? margin: 40rpx 60rpx;
? ? display: flex;
? ? flex-direction: row;
? ? justify-content: space-between;
? ? align-items: center;
? ? border-bottom: 1px solid #ddd;
? ? padding-bottom: 6rpx;
}
/*文本框本身*/
.input-container input {
? ? color: #999;
? ? flex: 1;
? ? height: 40px;
}
/*占位符樣式*/
.input-placeholder {
? ? color: #999;
}
/*清空按鈕*/
.input-container image {
? ? width: 22px;
? ? height: 22px;
}
.forgot {
? ? margin: 0 30rpx 40rpx 30rpx;
? ? text-align: right;
? ? font-size: 28rpx;
? ? color: #ccc;
}
.captcha {
? ? margin: 0 8rpx;
? ? color: #fff;
? ? fon-size: 25rpx;
? p t-a
.button[plain] {
? ? color: #09f;JS部分:
var timer = require('../../utils/timer.js');
Page({
? ? data: {
? ? ? ? verifyCode: '', //6617
? ? ? ? captchaLabel: '獲取驗(yàn)證碼',
? ? ? ? seconds: timer.length,
? ? ? ? captchaDisabled: false
? ? },
? ? onLoad: function() {
? ? },
? ? captcha: function(e) {
? ? ? ? var param = {
? ? ? ? ? ? phone: this.data.phone
? ? ? ? };
? ? ? ? // 禁用按鈕點(diǎn)擊
? ? ? ? this.setData({
? ? ? ? ? ? captchaDisabled: true
? ? ? ? });
? ? ? ? // 立刻顯示重發(fā)提示,不必等待倒計(jì)時(shí)啟動(dòng)
? ? ? ? this.setData({
? ? ? ? ? ? captchaLabel: timer.length + '秒后重新發(fā)送'
? ? ? ? });
? ? ? ? // 啟動(dòng)以1s為步長(zhǎng)的倒計(jì)時(shí)
? ? ? ? var interval = setInterval(() => {
? ? ? ? ? ? timer.countdown(this);
? ? ? ? }, 1000);
? ? ? ? // 停止倒計(jì)時(shí)
? ? ? ? setTimeout(function() {
? ? ? ? ? ? clearInterval(interval);
? ? ? ? }, timer.length * 1000);
? ? ? ? if (this.data.seconds == timer.length) {
? ? ? ? ? ? console.log('post');
? ? ? ? ? ? wx.showToast({
? ? ? ? ? ? ? ? title: '發(fā)送成功'
? ? ? ? ? ? });
? ? ? ? }
? ? },
})timer.js :
var length = 5;
function countdown(that) {
? ? console.log('count down');
? ? var seconds = that.data.seconds;
? ? console.log(seconds);
? ? var captchaLabel = that.data.captchaLabel;
? ? if (seconds <= 1) {
? ? ? ? captchaLabel = '獲取驗(yàn)證碼';
? ? ? ? seconds = length;
? ? ? ? that.setData({
? ? ? ? ? ? captchaDisabled: false
? ? ? ? });
? ? } else {
? ? ? ? captchaLabel = --seconds + '秒后重新發(fā)送'
? ? }
? ? that.setData({
? ? ? ? seconds: seconds,
? ? ? ? captchaLabel: captchaLabel
? ? });
}
module.exports = {
? ? countdown: countdown,
? ? length: length
}以上就是獲取驗(yàn)證碼功能的實(shí)現(xiàn)。
希望對(duì)大家的學(xué)習(xí)有所幫助,也希望大家多多支持腳本之家。
- 微信小程序?qū)崿F(xiàn)短信驗(yàn)證碼倒計(jì)時(shí)
- 微信小程序?qū)崿F(xiàn)驗(yàn)證碼倒計(jì)時(shí)效果
- 微信小程序?qū)崿F(xiàn)驗(yàn)證碼倒計(jì)時(shí)
- 微信小程序?qū)崿F(xiàn)手機(jī)獲取驗(yàn)證碼倒計(jì)時(shí)60s
- 微信小程序?qū)崿F(xiàn)發(fā)送短信驗(yàn)證碼倒計(jì)時(shí)
- 微信小程序的注冊(cè)頁(yè)面包含倒計(jì)時(shí)驗(yàn)證碼、獲取用戶信息
- 微信小程序項(xiàng)目實(shí)踐之驗(yàn)證碼倒計(jì)時(shí)功能
- 微信小程序?qū)崿F(xiàn)驗(yàn)證碼獲取倒計(jì)時(shí)效果
- 微信小程序?qū)崿F(xiàn)倒計(jì)時(shí)60s獲取驗(yàn)證碼
相關(guān)文章
JavaScript實(shí)現(xiàn)url地址自動(dòng)檢測(cè)并添加URL鏈接示例代碼
寫(xiě)一個(gè)簡(jiǎn)單的聊天系統(tǒng),發(fā)出Htpp的Url實(shí)現(xiàn)跳轉(zhuǎn)加上a標(biāo)簽,下面是具體的實(shí)現(xiàn),感興趣的朋友不要錯(cuò)過(guò)2013-11-11
window.onload 加載完畢的問(wèn)題及解決方案(下)
在IE中還可以在onreadystatechange事件里進(jìn)行判斷等方法。2009-07-07
JS實(shí)現(xiàn)鼠標(biāo)移上去顯示圖片或微信二維碼
本文給大家分享一段使用的js代碼實(shí)現(xiàn)鼠標(biāo)移入顯示圖片或微信二維碼樣式,代碼簡(jiǎn)單易懂,非常不錯(cuò),需要的朋友參考下吧2016-12-12
如何將HTML字符轉(zhuǎn)換為DOM節(jié)點(diǎn)并動(dòng)態(tài)添加到文檔中詳解
這篇文章主要給大家介紹了關(guān)于如何將HTML字符轉(zhuǎn)換為DOM節(jié)點(diǎn)并動(dòng)態(tài)添加到文檔中的相關(guān)資料,文中通過(guò)示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來(lái)一起看看吧2018-08-08
js實(shí)現(xiàn)網(wǎng)頁(yè)倒計(jì)時(shí)、網(wǎng)站已運(yùn)行時(shí)間功能的代碼3例
這篇文章主要介紹了js實(shí)現(xiàn)網(wǎng)頁(yè)倒計(jì)時(shí)、網(wǎng)站已運(yùn)行時(shí)間功能的代碼3例,需要的朋友可以參考下2014-04-04
html+javascript+bootstrap實(shí)現(xiàn)層級(jí)多選框全層全選和多選功能
想做一個(gè)先按層級(jí)排序并可以多選的功能,首先傾向于用多層標(biāo)簽式的,直接選定加在文本域里,接下來(lái)通過(guò)本文給大家介紹html+javascript+bootstrap實(shí)現(xiàn)層級(jí)多選框全層全選和多選功能,需要的朋友參考下2017-03-03
js學(xué)習(xí)總結(jié)_選項(xiàng)卡封裝(實(shí)例講解)
下面小編就為大家?guī)?lái)一篇js學(xué)習(xí)總結(jié)_選項(xiàng)卡封裝(實(shí)例講解)。小編覺(jué)得挺不錯(cuò)的,現(xiàn)在就分享給大家,也給大家做個(gè)參考。一起跟隨小編過(guò)來(lái)看看吧2017-07-07
javascript漢字拼音互轉(zhuǎn)的簡(jiǎn)單實(shí)例
下面小編就為大家?guī)?lái)一篇javascript漢字拼音互轉(zhuǎn)的簡(jiǎn)單實(shí)例。小編覺(jué)得挺不錯(cuò)的,現(xiàn)在就分享給大家,也給大家做個(gè)參考。一起跟隨小編過(guò)來(lái)看看吧2016-10-10
uniapp使用uni自帶websocket進(jìn)行即時(shí)通訊詳細(xì)步驟
在開(kāi)發(fā)程序過(guò)程中通信功能還是比較常用到的,下面這篇文章主要給大家介紹了關(guān)于uniapp使用uni自帶websocket進(jìn)行即時(shí)通訊的詳細(xì)步驟,文中通過(guò)代碼介紹的非常詳細(xì),需要的朋友可以參考下2023-11-11

