input 属性为 number,maxlength不起作用如何解决?

<input type="text"  maxlength="5" />   效果ok,

当 <input type="number"  maxlength="5" />时maxlength失效,长度可以无限输入。

解放方案:

<input type="number" oninput="if(value.length>5)value=value.slice(0,5)" />

很简单,搞定!

原文地址:https://www.cnblogs.com/zmdComeOn/p/9812487.html