獲取radio值的方法:
func:function(e){ var val=e.detail.value;//獲取radio值,類型:字符串 var val2=parseInt(val);//將字符串轉換爲number }
實例:app
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秒延遲用戶纔會反應過來本身剛纔選了哪個選項。ide
若是你想延遲必定時間再執行某一函數,就能用到這個定時器了!
setTimeout(方法,時間間隔 毫秒ms);函數
wxml:this
<!--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代碼url
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);spa