maxlength 不适用于输入类型 =“数字” 离子

Posted

技术标签:

【中文标题】maxlength 不适用于输入类型 =“数字” 离子【英文标题】:maxlength not working with input type="number" ionic 【发布时间】:2016-08-16 15:21:46 【问题描述】:

我尝试定义数字输入的最大长度。

 <label class="item item-input">
 <i class="icon ion-android-call placeholder-icon"></i>
 <input type="number"  placeholder="Phone number " maxlength="8">
 </label>

请问我该如何解决。

【问题讨论】:

确实如此。您可以使用类型 tel 然后它工作。顺便说一句,如果您将应用程序用于 ios,那么您没有 number 类型。 【参考方案1】:
   <input type="tel " maxlength="6">

【讨论】:

如果在桌面上使用网络浏览器,这不是一个可接受的答案,因为没有什么可以阻止您在字段中添加字母。到目前为止,Ionic 中似乎还没有针对这种情况的解决方案:-( 好的,这个链接让事情变得更清楚,同时使用 maxlength 和输入标签的模式属性的解决方法:***.com/questions/18510845/…【参考方案2】:
 <input type="tel" pattern="[0-9]*" maxlength="6">

这也将验证数字模式:)

【讨论】:

以上是关于maxlength 不适用于输入类型 =“数字” 离子的主要内容,如果未能解决你的问题,请参考以下文章