• 微信小程序单选按钮radio选中的值value的获取方法,setTimeout定时器的用法


    获取radio值的方法:

    func:function(e){
    	var val=e.detail.value;//获取radio值,类型:字符串
        var val2=parseInt(val);//将字符串转换为number
    }
    

    实例:

    laternext: function (e){
          // console.log(e);
          var val=e.detail.value;//获取radio值,类型:字符串
          var val2=parseInt(val);//将字符串转换为number
          var score2 = this.data.score;
          score2 += val2;
          this.setData({
            score: score2
          })
          // console.log(score2);
          setTimeout(this.next,500);
      },
    

    我遇到的情况:在单选按钮radio被选中时就刷新选项,设置0.5秒延迟观感会更好,有0.5秒延迟用户才会反应过来自己刚才选了哪一个选项。

    如果你想延迟一定时间再执行某一函数,就能用到这个定时器了!
    setTimeout(方法,时间间隔 毫秒ms);

    wxml:

    <!--pages/page02/page02.wxml-->
    <!-- <text>pages/page02/page02.wxml</text> -->
    <view id="bg">
    <progress percent="{{pro}}" show-info></progress>
    <view id="inside">
      <text id="question">{{titles[index]}}</text>
      <radio-group bindchange="laternext">
        <view id="rad">
        <radio value="{{selectA[index].value}}" checked="{{ck}}">{{selectA[index].name}}</radio>
        <radio value="{{selectB[index].value}}" checked="{{ck}}">{{selectB[index].name}}</radio>
        <radio value="{{selectC[index].value}}" checked="{{ck}}">{{selectC[index].name}}</radio>
        </view>
      </radio-group>
    </view>
    </view>
    

    部分js代码

    next: function () {
        var index2 = this.data.index;
        index2++;
        var score2 = this.data.score;
        var pro2 = this.data.pro;
        pro2 = (index2/8)*100;
        if (index2 == 8) {
          var app=getApp();
          app.data.scoresum = this.data.score;
          console.log(app.data.scoresum);
          wx: wx.redirectTo({
            url: '../page03/page03',
          })
          return false;
        }
        this.setData({
          index: index2,
          ck: false,
          pro : pro2
        })
      },
      laternext: function (e){
          // console.log(e);
          var val=e.detail.value;
          var val2=parseInt(val);
          var score2 = this.data.score;
          score2 += val2;
          this.setData({
            score: score2
          })
          // console.log(score2);
          setTimeout(this.next,500);
      },
    

    为什么绑定事件 bindchange=“laternext”,而不直接绑定next?

    如果直接绑定next,不写laternext函数,将e.detai.value获取值的语句写在next中,然后setTimeout(this.next,500),这样e是未定义undefined的,也就得不到选项的值,所以必须把获取值写在laternext函数里,再用setTimeout(next方法,时间间隔 毫秒ms);

  • 相关阅读:
    【视频剪辑】 Land of Dreams 航拍中国新疆篇 剪辑
    【视频剪辑】 2018年中国海空军掠影
    【视频剪辑】 成都雅安旅行vlog
    【PL/SQL】 学习笔记 (3)if 语句使用
    【PL/SQL】 学习笔记 (2)引用型变量和记录型变量
    dubbo远程方法调用的基本原理
    java8中的接口与时间操作
    接入天猫精灵auth2授权页面https发送ajax请求
    java8 流操作
    Lambda表达式和方法引用
  • 原文地址:https://www.cnblogs.com/BIG-BOSS-ZC/p/11807354.html
Copyright © 2020-2023  润新知