<input type="text" maxlength="5" /> 效果ok,当 <input type="number" maxlength="5" />时maxlength失效,长度可以无限输入。
解放方案:
<input type="number" οninput="if(value.length>5)value=value.slice(0,5)" />
使用
html代码解决
<
input
type="
number
"
maxlength
="5" on
input
="if(value.length>5)value=value.slice(0,5)" />
使用
js代码解决
//输入框为数字类型时防止
maxlength
属性不起作用
$('
input
').bind('
input
propertychange', function() {...
v-model="formAdd.xxx"
on
input
="if(value.length > 3) value=value.slice(0, 3)"
onkeypress="return (/[\d]/.test(String.fromCharCode(event.keyCode)));"
type="
number
"
placeho.