zoukankan      html  css  js  c++  java
  • 小程序手机登陆 定时器 清除定时器

    <form class="" bindsubmit="getData">
        <view >
            <input class="" name="iphone"  type="text" placeholder="手机号"></input>
        </view>
        <view >
            <input class="" name="code"  type="text" placeholder="验证码" ></input>
            <input class="" name="time"  type="buttom" value="{{time}}s"></input>
        </view >
        <view >
            <button bind:tap="sendFun" type="primary">发送消息</button>
        </view >
        <view >
            <button form-type="submit">验证用户</button>
        </view >
    </form>



    // pages/form/form.js
    Page({
    
      /**
       * 页面的初始数据
       */
      data: {
        timer: null,
        time:3
      },
    
      onLoad: function (options) {
    
      },
    
      sendFun(e){
        
        let time = this.data.time;
        this.data.timer = setInterval(() => {
          time--;
          if(time == 0) clearInterval(this.data.timer);//如果等于0 不继续减
          this.setData({
            time
          })
        }, 1000);//一秒减一次
        
      },
    
      getData(e){
        console.log(e);//获取的data值
      },
    
    })
    
    
    
    bindsubmit 获取的表单数据
    
    
    form-type="submit" button的标签 必须有才可提交
     
  • 相关阅读:
    bzoj3211 花神游历各国
    bzoj1010
    day8
    day6&7
    bzoj1087
    noi同步赛day1
    bzoj1076
    day3&4&5
    bzoj1079 dp
    cholesky分解
  • 原文地址:https://www.cnblogs.com/xm666/p/11354480.html
Copyright © 2011-2022 走看看