//获取用户复制到黏贴板中的文本内容
var content = window.clipboardData.getData("Text"); //js里面的粘贴事件onpaste function pasteCheck() { var content = window.clipboardData.getData("Text"); //获取用户复制到黏贴板中的文本内容for (var i = 0; i < content.length; i++) { var codeAsc = content.charCodeAt(i); //获取文本内容字符串每位的ASCII值var beginCodeAsc = '0'.charCodeAt(0); //获取0的ASCII值var endCodeAsc = '9'.charCodeAt(0); //获取9的ASCII值if (codeAsc < beginCodeAsc || codeAsc > endCodeAsc)//复制到黏贴板中的ASCII值,只能在0-9的区间{ return false;}}return true;} <input type="text" id="txtContent" οnkeydοwn="return ConstraintUserInput();" onpaste = "return pasteCheck();" />