小程序input組件失焦的使用


失去焦點就開始做數據請求判斷電話號碼是正確

 <view class='register-input-box'>
    <input class='register-input' placeholder="請輸入手機號" bindinput='phoneInput' bindblur="phoneOnBlur" value='{{phone}}' type="number" maxlength="11"></input>
  </view>
phoneOnBlur: function () {
    this.checkPhone()
},
checkPhone: function(sendSmsCode) {
    var that = this
    var phone = that.data.phone
    if (phone.length <= 0) {
      that.setData({
        errorMsg: '手機號不能為空',
      })
      return
    }
    xapi.request({
      url: getApp().apiHostNew + `/user/contact/${phone}/checkExist`,
      method: 'get'
    }).then( function(res) {
      if (res.data.code == 200) {
        if (res.data.data == true) {
          if (sendSmsCode) {
            that.sendSmsCode()
          }
          that.setData({
            showUserLoginTips: false
          })
        } else {
          that.setData({
            showUserLoginTips: true,
            smsCodeOk: false,
          })
        }
      } else {
        that.setData({
          showSendSmsCodeTips: false,
          smsCodeOk: false,
          errorMsg: res.data.message,
        })
      }
    })
  },


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM