您现在的位置是:网站首页> 编程资料编程资料
小程序实现简单验证码倒计时_javascript技巧_
2023-05-24
360人已围观
简介 小程序实现简单验证码倒计时_javascript技巧_
本篇文章主要讲关于小程序验证码倒计时的功能实现,供大家参考,具体内容如下


首先是wxml部分
样式部分:
/*提交按钮*/ 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: '获取验证码', seconds: timer.length, captchaDisabled: false }, onLoad: function() { }, captcha: function(e) { var param = { phone: this.data.phone }; // 禁用按钮点击 this.setData({ captchaDisabled: true }); // 立刻显示重发提示,不必等待倒计时启动 this.setData({ captchaLabel: timer.length + '秒后重新发送' }); // 启动以1s为步长的倒计时 var interval = setInterval(() => { timer.countdown(this); }, 1000); // 停止倒计时 setTimeout(function() { clearInterval(interval); }, timer.length * 1000); if (this.data.seconds == timer.length) { console.log('post'); wx.showToast({ title: '发送成功' }); } }, })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 = '获取验证码'; seconds = length; that.setData({ captchaDisabled: false }); } else { captchaLabel = --seconds + '秒后重新发送' } that.setData({ seconds: seconds, captchaLabel: captchaLabel }); } module.exports = { countdown: countdown, length: length }以上就是获取验证码功能的实现。
希望对大家的学习有所帮助,也希望大家多多支持。
您可能感兴趣的文章:
相关内容
- 微信小程序转盘抽奖的实现方法_javascript技巧_
- vuex store 缓存存储原理分析_vue.js_
- vue对象添加属性(key:value)、显示和删除属性方式_vue.js_
- JavaScript中关于递归与回溯的实例详解_javascript技巧_
- vue项目配置element-ui容易遇到的坑及解决_vue.js_
- 如何在vue中使用jsx语法_vue.js_
- Vue.extend实现组件库message组件示例详解_vue.js_
- uniapp使用H5调试时跨域问题解决_javascript技巧_
- Vue transx组件切换动画库示例详解_vue.js_
- nvm版本导致npm install报错Unexpected token '.'的解决办法_node.js_
