input type为数字(number)类型时maxlength属性不起作用
js解决方案
<input type="number" name="phone" id="getCode" placeholder="请填写手机号码" maxlength='11'>
$('#getCode').bind('input propertychange', function () {
if ($(this).attr("type") == "number") {
// 获取输入框的最大长度
var max= $(this).attr("maxlength");
// 如果输入的长度超过最大长度
if ($(this).val().length > max) {
$(this).val($(this).val().slice(0, max));
}
}
});