安卓输入框 input 组件
发布于 5 年前 作者 fengmin 2025 次浏览 来自 问答

<input type=‘text’ id=‘create-input’ value=’{{name}}’ bindinput=‘getInputName’ maxlength=‘10’></input>

安卓 input 组件, 回退删除的时候,  getInputName 里面的参数, e.detail.value 为空, 导致判断失误, 而输入框明明有内容

6 回复

我也有同样的问题,手机:小米5,2.1.1库。win10系统

wxml

<view class="weui-cells weui-cells_after-title">
  <view class="weui-cell weui-cell_input">
    <view class="weui-cell__bd">
      <input type="text" class="weui-input" bindinput="bindKeyInput" value="{{inputValue}}" />
    </view>
  </view>
</view>
 
<view class="weui-cells weui-cells_after-title">
  <view class="weui-cell weui-cell_input">
    <view class="weui-cell__bd">
      <input type="text" class="weui-input" bindinput="" value="{{inputValue0}}" />
    </view>
  </view>
</view>
 
<view class="weui-cells weui-cells_after-title">
  <view class="weui-cell weui-cell_input">
    <view class="weui-cell__bd">
      <input type="text" class="weui-input" bindinput="" value="{{test}}" />
    </view>
  </view>
</view>

JS:

data: {
  inputValue: 'B-',
  inputValue0: "",
  test: ""
},
 
bindKeyInput: function(e) {
  var val = e.detail.value
  var code = e.detail.keyCode
  var valLength = val.length
  if (valLength < 2) {
    this.setData({
      inputValue: 'B-'
    })
  } else if (valLength > 2 && valLength < 6) {
    this.setData({
      test: '暂停任务' + code,
      inputValue0: val
    })
  } else if (valLength == 6) {
    this.setData({
      test: '开始任务' + code
    })
  }
},

还有开发工具里没有detail.keyCode。

华为手机和锤子手机都重现了。每次回删, 被调用了两次, 第一次是错误的detail.value显示为空,第二次才是正确的。

已采用最新的基础库2.3.0,在锤子手机坚果Pro(安卓7.1.1)上依旧存在该问题。微信版本6.6.7

你好,确实是没有复现的说的问题,你是不是其他代码哪里写错了?

回退删除时input的值有一瞬间是空的 ,每删除一个就空一次

我刚才试了下,我手机没问题,代码复制你的

回到顶部