|
<body> 最大数: 98765 <input type=text value='123456' name=tt onkeydown=numInputCheck(this,98765)> 具体功能自己测试咯 :) </body> <script> //只能输入小于最大数且是正整数的脚本 function numInputCheck(o,m){ var d; if(',48,49,50,51,52,53,54,55,56,57,96,97,98,99,100,101,102,103,104,105,8,9,13,'.indexOf(',' + event.keyCode + ',')==-1){ event.returnValue=null; } if(m!=null){ d = event.keyCode >= 96 ? event.keyCode - 48 : event.keyCode; if(document.selection.createRange().duplicate().text=='' && (o.value+String.fromCharCode(d))>m){ event.returnValue=null;o.value=m; }else if(',8,9,13,'.indexOf(',' + d + ',')==-1&&document.selection.createRange().duplicate().text==''&&o.value.indexOf('0')==0){ o.value=''; } } } </script> |