如何限制用户在jquery中使用按键事件声明为数字文本框的文本框中复制和粘贴字符
答案 0 :(得分:0)
尝试以下
<强> HTML 强>
<input type="text" ID="TextBox1" runat="server" >
<强> JS 强>
$(document).ready(function () {
$("#TextBox1").keypress(function (e) {
//if the letter is not digit then display error and don't type anything
if (e.which != 8 && e.which != 0 && (e.which < 48 || e.which > 57)) {
//display error message
$("#errmsg").html("Digits Only").show().fadeOut("slow");
return false;
}
});
});
$(document).ready(function() {
$('#TextBox1').bind('copy paste cut',function(e) {
e.preventDefault(); //disable cut,copy,paste
});
});
这将禁用复制,粘贴功能主义者,它只允许用户输入数字
的 DEMO 强>