微信小程序清空input操作,实测安卓机需要点两次才能清空。
近日在写手机号获取验证登录的时候,输入手机号清空的时候发现安卓手机需要点击两次才能清空,为啥要点2次才能清空?
- 点第一次失去焦点,点第二次input才被清空
- wxml
<input value="{{phone}}" name="phone" bindblur="onBlur" bindinput='onInput' data-t="phone" placeholder="请输入手机号" maxlength="11" placeholder-class="placeholder-class" type="number" focus='{{isfocus}}'></input>
<image bindtap="clearPhone" wx:if="{{phone}}" src="/images/icon_del.png"></image>
- js
data: {
phone:'',
isfocus:false
},
clearPhone(e){
this.setData({
isfocus: false,
phone: ''
})
}
- 解决方案
clearPhone(e) {
wx.hideKeyboard({
complete: res => {
this.setData({
isfocus: false,
phone: ''
})
}
})
this.setData({
isfocus: false
}, () => {
this.setData({
phone: ''
})
})
},