<input type="text" maxlength="6" /> 效果ok <input type="number" maxlength="6" /> 当input type = number 时maxlength失效,长度可以无限输入。
解放方案: oninput事件 当长度超过截取
<input type="number" oninput="if(value.length>11)value=value.slice(0,11)
本文探讨了HTML中input type=number元素的maxlength属性失效的问题,并提供了一个实用的解决方案:通过oninput事件来限制用户输入的长度。
<input type="text" maxlength="6" /> 效果ok <input type="number" maxlength="6" /> 当input type = number 时maxlength失效,长度可以无限输入。
解放方案: oninput事件 当长度超过截取
<input type="number" oninput="if(value.length>11)value=value.slice(0,11)
1184

被折叠的 条评论
为什么被折叠?