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)" />

很简单,搞定!

猜你喜欢

转载自www.cnblogs.com/520BigBear/p/9012708.html