小程序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