function doKeyPress(maxLen,obj){
var str=obj.value;
var oSR=document.selection.createRange();
if(str.length<maxLen){
return true;
}else if(oSR.text.length>0){
return true;
}else{
return false;
}
}
function checkPaste(maxLen,obj){
var str = obj.value;
var oSR = document.selection.createRange();
var strData = clipboardData.getData('text');
var iLenPaste = maxLen-str.length+oSR.text.length;
oSR.text = strData.substring(0,iLenPaste);
return false;
}
然后 οnkeypress="event.returnValue=dokeyPress(10000,this);" onPaste="event.returnValue=checkPaste(10000,this);"