Ios input type为number时仍然能输入中文

oninput不能像onkeydown等事件一样阻止冒泡和默认行为。

解决的方案为

1.在keydown时存储旧值,所有input共用一个变量就好,采用正则等方式检验旧值,通过则保存,不通过不保存

2.oninput时对本次加入的值进行正则方式校验

3.如果通过校验,不用进行操作。不通过时,对input双向绑定的值进行旧值赋值,这可能会触发input的更新,就不会出现中文,也没有闪现的情况,表现就是中文没有输入进去。

 

onAmountKeyDown(event) {
//处理ios问题:input type是number,但是还能输入中文
if (this.amountExp.test(event.target.value)) {
this.lastInputValue = event.target.value
}
//console.log("onAmountKeyDown: " + this.lastInputValue)
},
onAmountInput(event) {
const value = event.target.value
//console.log("onAmountInput: " + value)
//处理ios问题:input type是number,但是还能输入中文
if (!this.amountExp.test(value)) {
this.amount = this.lastInputValue
}

if (value.length > this.amountMaxLen) {
this.amount = value.slice(0, this.amountMaxLen)
}
},
posted @ 2019-10-18 09:34  飞晨信息  阅读(1091)  评论(0)    收藏  举报