Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

input 输入框数字校验 #18

Open
K-Kevin opened this issue Mar 27, 2020 · 0 comments
Open

input 输入框数字校验 #18

K-Kevin opened this issue Mar 27, 2020 · 0 comments
Labels
踩坑

Comments

@K-Kevin
Copy link
Owner

K-Kevin commented Mar 27, 2020

问题:h5 input 输入框 type=number 时,输入 1.2. 最后一个小数点不会触发 onChange

<input type="number" value={inputValue} onChange={(e)=>{this.bindInput(e)}} />

bindInput = (e) => {
   console.log('###',e.target.value)
}

情况一:

输入 12,2,100 这样的整数,正常打印出 12,2,100

情况二:

输入 12. 只会打印出 12 如果输入 12.3 则可以打印出 12.3

情况三:

输入 1.23 打印出 1.23 输入 1.23. 也是输入 1.23

总结:

想要对 type= number 时进行小数点校验,暂无合适的方案,可以考虑自定义键盘,type 默认类型是可以做到小数点监测的。

如果项目中有使用到 antd,则使用 antd 中的自定义键盘,带上校验规则,完美适配;

@K-Kevin K-Kevin added the 踩坑 label Mar 27, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
踩坑
Projects
None yet
Development

No branches or pull requests

1 participant