解决input为number类型时maxlength无效的问题

使用input数字number类型的时候maxlength无效,假设需要控制输入数量为18,可以用以下方式:

其他类型有效:
<input type="text" maxlength="18" />
当 type="number"时无效:
<input type="number" maxlength="18" />

有效:

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

猜你喜欢

转载自www.cnblogs.com/SPHmomo/p/12935801.html