uni-app input 设置type=digit时,在部分机型(ios,鸿蒙4.0)上输入小数点,光标会跳到最左边

uni-app input 设置type=digit时,在部分机型(ios,鸿蒙4.0)上输入小数点,光标会跳到最左边

7 回复

使用 4.17 ios 会出现这样的情况?录个屏看看

更多关于uni-app input 设置type=digit时,在部分机型(ios,鸿蒙4.0)上输入小数点,光标会跳到最左边的实战系列教程也可以访问 https://www.itying.com/category-93-b0.html


4.15的hx

回复 2***@qq.com: 使用 4.17 alpha 吧,4.17 修复的

附件

解决了吗这个问题, 我升级到4.15版本,也这个问题,华为鸿蒙手机,输入小数点光标会跳到最左边

您好,这个问题解决了吗? 现在最新版还是会这样

uni-app 中,当 input 组件的 type 设置为 digit 时,部分机型(如 iOS 和鸿蒙 4.0)在输入小数点时,光标可能会跳到最左边。这是因为这些系统在处理 digit 类型的输入时,对小数的处理方式与预期不一致。

解决方案

  1. 使用 type="text" 并自定义输入验证: 你可以将 type 设置为 text,然后通过自定义逻辑来验证输入是否为数字和小数点。

    <template>
      <input type="text" v-model="inputValue" @input="handleInput" />
    </template>
    
    <script>
    export default {
      data() {
        return {
          inputValue: ''
        };
      },
      methods: {
        handleInput(event) {
          const value = event.target.value;
          // 只允许数字和小数点
          const filteredValue = value.replace(/[^0-9.]/g, '');
          // 确保只有一个小数点
          const parts = filteredValue.split('.');
          if (parts.length > 2) {
            this.inputValue = parts[0] + '.' + parts.slice(1).join('');
          } else {
            this.inputValue = filteredValue;
          }
        }
      }
    };
    </script>
    
  2. 使用 type="number" 并处理小数点: 你可以将 type 设置为 number,然后通过 @input 事件来处理输入。

    <template>
      <input type="number" v-model="inputValue" @input="handleInput" />
    </template>
    
    <script>
    export default {
      data() {
        return {
          inputValue: ''
        };
      },
      methods: {
        handleInput(event) {
          const value = event.target.value;
          // 确保只包含数字和小数点
          this.inputValue = value.replace(/[^0-9.]/g, '');
        }
      }
    };
    </script>
    
  3. 使用 inputmode="decimal": 你可以尝试使用 inputmode="decimal",这可能会在某些设备上更好地处理小数输入。

    <template>
      <input inputmode="decimal" v-model="inputValue" />
    </template>
回到顶部