问题描述
我尝试为maxlength
,max
属性添加ion-input
,但是它没有按预期工作.
I have tried to add ion-input
for maxlength
, max
attribute but it's not working as per expectation.
<ion-input type="number" placeholder="*" maxlength="1"></ion-input>
<ion-input type="number" placeholder="*" max="1"></ion-input>
有人知道相同的解决方案吗?
Anyone knows the solution for the same?
谢谢
推荐答案
根据此帖子:
最大长度不适用于输入类型="number"
Maxlength doesn't work on input type="number"
这里建议一种替代方法: https://github.com/ionic-team/ionic/issues/7072 其中dilhan119建议使用type ="tel"
One alternative is suggested here: https://github.com/ionic-team/ionic/issues/7072where dilhan119 suggests using type="tel"
一个可靠的解决方案是使用表单验证器,这将阻止表单提交(并可能向用户显示错误): https://www.joshmorony.com/advanced-forms-validation-in-ionic-2/
A robust solution is to use a form validator, which will prevent form submission (and can show the user an error): https://www.joshmorony.com/advanced-forms-validation-in-ionic-2/
这篇关于Ionic-3离子输入最大长度属性不起作用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!