您现在的位置:首页 >> 前端 >> 内容

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

时间:2016/12/10 13:41:00 点击:

  核心提示:input type=text maxlength=6 / 效果okinput type=number maxlength=6 /当input type = number 时maxlength失效,长...
<input type="text" maxlength="6" /> 效果ok

<input type="number" maxlength="6" />

当input type = number 时maxlength失效,长度可以无限输入。

解放方案:

oninput事件 当长度超过截取

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

 

Tags:IN NP PU UT 
作者:网络 来源:jiegeng223