uni-app input标签 type为number时在ios上可以输入中文字 当包含中文字时 此input标签绑定的值为空
uni-app input标签 type为number时在ios上可以输入中文字 当包含中文字时 此input标签绑定的值为空
信息类别 | 详细信息 |
---|---|
产品分类 | uniapp/App |
PC开发环境操作系统 | Windows |
PC开发环境操作系统版本号 | Win10企业版 |
HBuilderX类型 | 正式 |
HBuilderX版本号 | 3.1.8 |
手机系统 | iOS |
手机系统版本号 | IOS 14 |
手机厂商 | 苹果 |
手机机型 | iphone8 |
页面类型 | vue |
打包方式 | 云端 |
项目创建方式 | HBuilderX |
操作步骤:
input标签 type为number时在ios上 可以输入中文字
当包含中文字时 此input标签绑定的值为空
预期结果:
input标签 type为number时在ios上 可以输入中文字
当包含中文字时 此input标签绑定的值为空
实际结果:
input标签 type为number时在ios上 可以输入中文字
当包含中文字时 此input标签绑定的值为空
bug描述:
input标签 type为number时在ios上 可以输入中文字
当包含中文字时 此input标签绑定的值为空
更多关于uni-app input标签 type为number时在ios上可以输入中文字 当包含中文字时 此input标签绑定的值为空的实战教程也可以访问 https://www.itying.com/category-93-b0.html
更多关于uni-app input标签 type为number时在ios上可以输入中文字 当包含中文字时 此input标签绑定的值为空的实战教程也可以访问 https://www.itying.com/category-93-b0.html
这是一个iOS系统的已知限制。当input的type设置为number时,iOS系统会启用数字键盘,但系统仍允许通过长按或其他方式输入中文。由于number类型的输入框预期只接受数字,当包含中文字符时,系统会将其视为无效值,导致绑定的数据为空。
建议的解决方案:
- 将input类型改为
type="digit"
,这会限制只能输入数字和小数点 - 使用
type="text"
并结合正则表达式过滤非数字字符 - 在输入事件中通过JavaScript验证和清理输入值
示例代码:
<input type="text" [@input](/user/input)="filterNumber" v-model="inputValue" />
<script>
export default {
methods: {
filterNumber(e) {
this.inputValue = e.detail.value.replace(/[^\d]/g, '')
}
}
}
</script>