在uni-app ios端 input type 为 number 时,键盘没有小数点,type 为digit 时数字后紧跟小数点,光标会跑到最前面。
在uni-app ios端 input type 为 number 时,键盘没有小数点,type 为digit 时数字后紧跟小数点,光标会跑到最前面。
| 开发环境 | 版本号 | 项目创建方式 |
|----------|--------|--------------|
| Mac | macOS Ventura 13.7.4 | HBuilderX |
产品分类:uniapp/App
PC开发环境操作系统:Mac
HBuilderX类型:正式
HBuilderX版本号:4.56
手机系统:iOS
手机系统版本号:iOS 18
手机厂商:苹果
手机机型:苹果12
页面类型:vue
vue版本:vue3
打包方式:云端
操作步骤:
<input type="digit" placeholder="输入价格" />
```
预期结果:
<input type="digit" placeholder="输入价格" />
实际结果:
<input type="digit" placeholder="输入价格" />
bug描述: 在ios端 input type 为 number 时,键盘没有小数点,type 为digit 时数字后紧跟小数点,光标会跑到最前面。
更多关于在uni-app ios端 input type 为 number 时,键盘没有小数点,type 为digit 时数字后紧跟小数点,光标会跑到最前面。的实战教程也可以访问 https://www.itying.com/category-93-b0.html
2 回复
这是视频
更多关于在uni-app ios端 input type 为 number 时,键盘没有小数点,type 为digit 时数字后紧跟小数点,光标会跑到最前面。的实战教程也可以访问 https://www.itying.com/category-93-b0.html
这是iOS系统对数字输入键盘的默认行为问题。针对您描述的情况,我给出以下分析:
-
关于
type="number"
没有小数点的问题: 这是iOS系统的默认行为,数字键盘默认不显示小数点。可以通过添加pattern="[0-9]*"
属性来强制显示数字键盘,但依然不会显示小数点。 -
关于
type="digit"
光标跳转问题: 这是iOS系统在处理数字和小数点输入时的已知问题。当输入数字后立即输入小数点时,系统会错误处理光标位置。
解决方案建议:
- 使用
type="text"
配合正则验证:
<input
type="text"
pattern="[0-9]*\.?[0-9]*"
inputmode="decimal"
@input="handleInput"
/>
- 在Vue中实现输入控制:
const handleInput = (e) => {
e.target.value = e.target.value.replace(/[^0-9.]/g, '')
}