怎样点击按键跳出循环?

小程序 文章 2020-08-18 12:01 599 0 全屏看文

AI助手支持GPT4.0

怎样点击按键跳出循环?How to click the button to jump out of the loop?

怎样点击按键跳出循环?
 点击按键stop,start按键获取不了m值,导致跳不出循环,有没有更理想的办法?1、index.js   Page({bindinput: function (e) {    this.setData({      userName: e.detail.value    })  },start: function () {     var m=this.data.m console.log('m------//',m)    for (var i = 0; i < 6; ++i) {        console.log('bhtime------//',i)       if (i==5){var i=0}    this.setData({      userName: i    })  if(m==5break;}     },  stop: function () {         console.log('stop')           this.setData({      m: 5    })       },})2、index.wxml     class=   "button1" catchtap=   "start">start        class=    "button2" catchtap=    "stop">stop          class=     "c">                class=      "check-box"  maxlength=      '10'  value=      "{{userName}}"       type=      "text" bindinput=      'bindinput' >              

Click the stop button, the start button can not get the m value, resulting in the loop can not jump out, is there a better way? 1、 index.js    Page({bindinput: function (e) {     this.setData ({      userName: e. detail.value     })  },start: function () {     var m= this.data .m  console.log ('m------//',m)    for (var i = 0; i < 6; ++i) {         console.log ('bhtime------//', i)       if (i==5){var i=0}     this.setData ({      userName: i    })  if(m==5) break;}     },  stop: function () {          console.log ('stop')            this.setData ({      m: 5    })       }, })2、 index.wxmlclass= "button1" catchtap="start">start class="button2" catchtap="stop">stop class="c">class="check-box"  maxlength='10'  value="{{userName}}" type="text" bindinput='bindinput' >

回答:

Sven scum་ཅ་:

把循环封装,点击按键调用封装你的循环进行中断


微喵网络:

弄一个 [ 能复现问题的简单的 ] 代码片段

https://developers.weixin.qq.com/miniprogram/dev/devtools/minicode.html

stop eating:

这是什么功能?写着玩的?

-EOF-

AI助手支持GPT4.0