在线观看不卡亚洲电影_亚洲妓女99综合网_91青青青亚洲娱乐在线观看_日韩无码高清综合久久

鍍金池/ 問(wèn)答/HTML/ 微信小程序input失焦異常

微信小程序input失焦異常

1.問(wèn)題描述

初始打開(kāi)頁(yè)面,input框自動(dòng)聚焦,在輸入n位數(shù)字后自動(dòng)觸發(fā)事件進(jìn)行業(yè)務(wù)處理,結(jié)果以頁(yè)面底部彈框形式展示,同時(shí)input失焦。
但目前問(wèn)題是,底部彈框出現(xiàn)后,input再次獲得焦點(diǎn),導(dǎo)致鍵盤彈起,阻擋住底部彈框。
只有在剛進(jìn)入頁(yè)面,第一次輸入后會(huì)出現(xiàn)這個(gè)問(wèn)題,保留在當(dāng)前頁(yè)面,第二次輸入時(shí)一切正常。

2.相應(yīng)截圖

正常
clipboard.png

異常
clipboard.png

異常時(shí)輸出
clipboard.png

3.代碼片段

<input type="number" focus="{{focus && !blurFlag}}" value="{{doSomthing}}" bindinput="inputNum" bindfocus="bindfocus" bindblur="bindblur"/>
<view class="mask" wx:if="{{showModal}}"></view>
<view class="modal {{ modalTypeMap[modalType] }}" hidden="{{!showModal}}">
    <view>{{ msg }}</view>
</view>

doSomething(e) {
    this.setData({
      fetchCode: e.detail.value,
      blurFlag: false,
    })
    if (e.detail.value.length === 11) {
      this.setData({
        focus: false,
        blurFlag: true,
      })
      this.loadOrder()
    }
  }
loadOrder(e) {
    if (this.data.fetchCode.length === 11) {
      app.request()
        .header('content-type', 'application/json')
        .post(url)
        .query({
          token: app.get('token')
        })
        .send(params)
        .end()
        .then(res => res.body)
        .then(({code, data}) => {
          if ( code === 200) {
            let modalType = 1
            let msg = this.data.msg
            if (data.success) {
              modalType = 1
            } else {
              modalType = 3,
              msg = data.failReason
            }
            this.setData({
              focus: false,
              modalType: modalType,
              msg: msg,
              showModal: true,
            })
          }
          console.log('loadOrder end')
          console.log('focus: ' + this.data.focus)
        })
    }
  }
bindfocus() {
    if (this.data.blurFlag) {
      this.setData({
        focus: false
      })
      console.log('bindfocus blurFlag: ' + this.data.blurFlag)
      console.log('focus: ' + this.data.focus)
    } else {
      this.setData({
        focus: true
      })
      console.log('bindfocus blurFlag: ' + this.data.blurFlag)
      console.log('focus: ' + this.data.focus)
    }
  }
bindblur() {
    this.setData({
      focus: false
    })
    console.log('bindfblur blurFlag: ' + this.data.blurFlag)
    console.log('focus: ' + this.data.focus)
  }

4.分析問(wèn)題

bindfocus和bindblur事件、blurFlag變量只是為了排除檢測(cè)問(wèn)題而設(shè)置的。
根據(jù)控制臺(tái)輸出結(jié)果發(fā)現(xiàn),在業(yè)務(wù)處理結(jié)束后,代碼設(shè)置focus=false觸發(fā)了一次bindblur, 另外未知因素觸發(fā)了一次bindfocus。這一次bindfocus到底是什么行為觸發(fā)的,并沒(méi)有找到。
而且,為什么只進(jìn)入頁(yè)面后第一次輸入會(huì)出現(xiàn)這個(gè)問(wèn)題,onload中并沒(méi)有進(jìn)行任何涉及聚焦失焦的操作,只是data中初始化focus為true、blurFlag為false。
微信版本為6.6.7
請(qǐng)教各位大神,在線等。

回答
編輯回答
紓惘

同樣遇到這樣的問(wèn)題,input在失去焦點(diǎn)之后,莫名原因再次獲得焦點(diǎn),導(dǎo)致輸入法會(huì)再次彈出;
嘗試用disabled禁止輸入,達(dá)到不讓輸入法彈出,發(fā)現(xiàn)無(wú)效

想知道樓主怎么解決這個(gè)的

2018年4月29日 00:14
編輯回答
萌面人

小程序的坑很多,他們的品控一向成問(wèn)題,所以我一般不會(huì)去特別深入研究到底是哪兒的問(wèn)題,研究一下沒(méi)有結(jié)果就想辦法繞過(guò)去。

這個(gè)地方要不你不要用 focus,用 disabled 試一試?

2017年3月10日 00:46