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

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

浏览量:3173 时间: 来源:BIG_BOSS_ZC

获取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--!-- textpages/page02/page02.wxml/text --view id="bg"progress percent="{{pro}}" show-info/progressview 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);

版权声明

即速应用倡导尊重与保护知识产权。如发现本站文章存在版权问题,烦请提供版权疑问、身份证明、版权证明、联系方式等发邮件至197452366@qq.com ,我们将及时处理。本站文章仅作分享交流用途,作者观点不等同于即速应用观点。用户与作者的任何交易与本站无关,请知悉。

产品经理

手机 : 13312967497

擅长 : 小程序流量变现

扫码领取礼包

热门模板

  • 头条
  • 搜狐
  • 微博
  • 百家
  • 一点资讯
  • 知乎