Home >WeChat Applet >Mini Program Development >Sample code for WeChat applet to implement countdown function for sending text messages

Sample code for WeChat applet to implement countdown function for sending text messages

黄舟
黄舟Original
2017-09-12 09:20:142809browse

This article mainly introduces the countdown function of sending text messages in the WeChat applet. Friends who need it can refer to it

After clicking

Code


<form bindsubmit="formSubmit" bindreset="formReset"> 
<view class="fidpas"> 
 <input type="number" class="fidpas_inp"placeholder-class="lgin_place" placeholder="请输入手机号" name="phonenumber" /> 
 <input type="number" class="fidpas_inp2"placeholder-class="lgin_place" placeholder="请输入短信验证码" name="msg" /> 
 <button class="{{sendmsg}}" bindtap="sendmessg">{{getmsg}}</button> 
</view> 
<button class="lgbut" formType="submit">下一步</button> 
</form> 
data: { 
 sendmsg: "sendmsg", 
 getmsg:"获取短信验证码", 
 }, 
 /** 
 * 获取短信验证码 
 */ 
 sendmessg:function(e){ 
 if (timer==1){ 
 timer=0 
 var that=this 
 var time=60 
 that.setData({ 
 sendmsg:"sendmsgafter", 
 }) 
 var inter=setInterval(function(){ 
  that.setData({ 
  getmsg: time + "s后重新发送", 
  }) 
  time-- 
  if(time<0){ 
  timer=1 
  clearInterval(inter) 
  that.setData({ 
   sendmsg: "sendmsg", 
   getmsg: "获取短信验证码", 
  }) 
  } 
 },1000)} 
 },

Idea: Set the style and content after BUTTON as variables, click setData to change them

Summarize

The above is the detailed content of Sample code for WeChat applet to implement countdown function for sending text messages. For more information, please follow other related articles on the PHP Chinese website!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn