jQuery限制文本框输入,包含粘贴。
0) {
return (this.value.length <= len);
}
}
return true;
});
//粘贴
$(document).on("paste",function () {
var len = $(this).data("maxlength") || 0;
if (len > 0) {
return ((this.value.length + event.clipboardData.getData('Text').length) <= len);
}
return true;
});
$(document).on("keyup input",function (e) {
var keyCode = e.keyCode || e.which || e.charCode;
if (keyCode == 46 || keyCode == 8) {
}
else {
var len = $(this).data("maxlength") || 0;
if (len > 0) {
if (this.value.length > len) {
this.value = com.cutStr(this.value,len,"");
}
}
}
});
});
原文链接:https://www.f2er.com/jquery/42621.html