微信小程序实现获取手机号60s倒计时

本文实例为大家分享了微信小程序实现获取手机号60s倒计时的具体代码,供大家参考,具体内容如下

1.效果:点击获取》60s倒计时》重新获取

2.wxml

<view class="cu-form-group" style="border-top: 1rpx solid #eee;">
      <view class="title">手机号</view>
      <input name='phone' placeholder="请输入新手机号"  value="{{phone}}" type="number" bindinput="inputBindPhone" ></input>
    </view>  
 
<view class="cu-form-group" style="border-bottom: 1rpx solid #eee;">
      <view class="title">验证码</view>
      <input name='code' placeholder="请输入验证码" value="{[code]}" type="number" bindinput="inputBindCode"></input>
      <button class="cu-btn shadow {{disabled ? '':'bg-blue'}}" style="width:180rpx;height:72rpx;"   bindtap='sendRegistCode'>{{time}}</button>
</view>

3.js

Page({
 
  /**
   * 页面的初始数据
   */
  data: {
    disabled:false,
    time: '点击获取',
    currentTime: 60,
    phone: '',
    code: '',
  },
 
  
  // 新手机号
  inputBindPhone: function (e) {
    console.log(e.detail.value)
    this.setData({
      phone: e.detail.value
    })
  },
  // 验证码
  inputBindCode: function (e) {
    console.log(e.detail.value)
    this.setData({
      code: e.detail.value
    })
  },
 
  sendRegistCode: function(e){
    var that = this;
    var currentTime = that.data.currentTime;
      var interval;
      that.setData({
        time: currentTime + 's',
        disabled: true,
      })
      interval = setInterval(function () {
        that.setData({
          time: (currentTime - 1) + ' s'
        })
        currentTime--;
        if (currentTime <= 0) {
          clearInterval(interval)
          that.setData({
            time: '重新获取',
            currentTime: 60,
            disabled: false
          })
        }
      }, 1000)
},
 
 
  formSubmit: function (e) {
    var that = this,
      value = e.detail.value,
      formId = e.detail.formId;
    // value.phone = this.data.phone
    // value.code = this.data.code
 
 
    var mPattern = /^1[3-9]\d{9}$/; //手机号码
    var authReg = /^\d{4}$/; //4位纯数字验证码
    var notempty = /^\\S+$/; //非空
 
    if (this.data.phone == '' || this.data.phone == undefined) {
      return wx.showToast({
        title: '请输入手机号码',
        icon: 'none'
      })
    } else if (!mPattern.test(this.data.phone)) {
      return wx.showToast({
        title: '请输入正确的手机号码',
        icon: 'none'
      })
 
    } else {
      value.phone = this.data.phone
      console.log('value.phone', value.phone)
    }
 
 
    if (value.code == '' || value.code == undefined) {
      return wx.showToast({
        icon: 'none',
        title: '请输入验证码',
      });
    } else if (!authReg.test(this.data.code)) {
      return wx.showToast({
        title: '请输入正确的验证码',
        icon: 'none'
      })
 
    } else {
      value.code = this.data.code
      console.log('value.code', value.code)
    }
 
 
    wx.showToast({
      title: '提交成功',
      icon: 'success',
      duration: 2000,
      success: function () {
         console.log(value)
        that.setData({
          code: '',
          phone: '' 
        })
      }
    })
 
  },
  
 
})

以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持我们。

(0)

相关推荐

  • 微信小程序实现团购或秒杀批量倒计时

    本文实例为大家分享了微信小程序实现批量倒计时的具体代码,供大家参考,具体内容如下 效果图 实现思路 微信小程序实现倒计时,可以将倒计时的时间进行每一秒的计算和渲染! JS 模拟商品列表数据 goodsList: 在 onLoad 周期函数中对活动结束时间进行提取: 建立时间格式化函数 timeFormat: 建立倒计时函数 countDown: 在 onLoad 周期函数的提取结尾执行倒计时函数 countDown. 倒计时函数详解 获取当前时间,同时得到活动结束时间数组: 循环活动结束时间数组

  • 微信小程序实现订单倒计时

    本文实例为大家分享了微信小程序实现订单倒计时的具体代码,供大家参考,具体内容如下 之前在做一个有拼团功能项目的时候遇到过倒计时的问题,由于当时技术不熟在这方面耽搁了好些时间,所以这里整理出来希望能为后来人提供些许启发. 1.实现思路 求出发起拼团时间与拼团结束时间的时间差 再将时间差格式化得到我们想要的格式如: 时间每秒递减使用了 setTimeout(this.setTimeCount,1000);这个函数,让这个函数每隔一秒执行一次. 效果图: 2.实现中的难点 若是要实现单个倒计时如60s

  • 微信小程序实现日期格式化和倒计时

    本文实例为大家分享了微信小程序实现日期格式化和倒计时的具体代码,供大家参考,具体内容如下 首先看看日期怎么格式化 第一种: Date.prototype.Format = function (fmt) { //author: meizz var o = { "M+": this.getMonth() + 1, //月份 "d+": this.getDate(), //日 "h+": this.getHours(), //小时 "m+&q

  • 微信小程序倒计时功能实例代码

    本实例的主要功能是:单击按钮弹出一个半透明的弹出层,在规定的时间后才能激活关闭按钮,关闭弹出层. wxml部分 <view class="wrap"> <view class="btns"> <button formType="submit" class="btn" hover-class='btn_on' bindtap='show'>使用说明</button> <but

  • 微信小程序显示倒计时功能示例【测试可用】

    本文实例讲述了微信小程序显示倒计时功能.分享给大家供大家参考,具体如下: 微信小程序中显示倒计时: index.wxml: <view class='countdown'>剩:<text style='color:#6B4EFD'> {{countDownDay}} </text> 天 <text style='color:#6B4EFD'>{{countDownHour}} </text> <text style='color:#6B4E

  • 微信小程序之发送短信倒计时功能

    点击后 代码 <form bindsubmit="formSubmit" bindreset="formReset"> <view class="fidpas"> <input type="number" class="fidpas_inp"placeholder-class="lgin_place" placeholder="请输入手机号&quo

  • 微信小程序注册60s倒计时功能 使用JS实现注册60s倒计时功能

    微信小程序+WEB使用JS实现注册[60s]倒计时功能开发步骤: 1.效果图: 2.页面仅仅利用了JS的相关功能,包含:wxml.js.wxss 2.1wxml页面代码: <text>绑定手机</text> <form bindsubmit="bindMobile"> <view class="form_group"> <text>手 机:</text> <input type="

  • 微信小程序实现倒计时60s获取验证码

    本文实例为大家分享了微信小程序倒计时获取验证码的具体代码,供大家参考,具体内容如下 1.工具类(引用微信小程序提供的工具类) countdown.js class Countdown { constructor(options = {}) { Object.assign(this, { options, }) this.__init() } /** * 初始化 */ __init() { this.page = getCurrentPages()[getCurrentPages().length

  • 微信小程序 倒计时组件实现代码

    功能: 适用于电商应用的限时团购.商品秒杀等 先来看下最终效果: git源:http://git.oschina.net/dotton/CountDown 分步骤-性子急的朋友,可以直接看最后那段代码. wxml文件放个text <text>second: {{second}} micro second:{{micro_second}}</text> 在js文件中调用 function countdown(that) { var second = that.data.second

  • 微信小程序动态显示项目倒计时效果

    本文实例为大家分享了微信小程序动态显示项目倒计时的具体代码,供大家参考,具体内容如下 1.一般我们说的显示秒杀都是指的单条数据,循环我没做. 效果: 2.wxml代码: <p> <block wx:if="{{total_micro_second<=0}}">剩余时间:已经截止</block> <block wx:if="{{clock!='已经截止'}}">剩余时间:{{clock}}</block>

随机推荐