Ionic-3离子输入最大长度属性不起作用 [英] Ionic-3 ion-input maxlength attribute not working

查看:121
本文介绍了Ionic-3离子输入最大长度属性不起作用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我尝试为maxlengthmax属性添加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/7072 where dilhan119 suggests using type="tel"

一个可靠的解决方案是使用表单验证器,这将阻止表单提交(并可能向用户显示错误):

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离子输入最大长度属性不起作用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆