<div class="htmlarea"> <textarea id="runcode73946"> 最大数: 98765 <input type="text" value="123456" name="tt" onkeydown="numInputCheck(this,98765)"> 具体功能自己测试咯 :) <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> </textarea><br><input onclick="runEx('runcode73946')" type="button" value="运行代码"> <input onclick="doCopy('runcode73946')" type="button" value="复制代码"> <input onclick="doSave(runcode73946)" type="button" value="保存代码">[Ctrl+A 全选 注:<a href="http://www.jb51.net/article/23421.htm" title="查看具体详情" target="_blank">如需引入外部Js需刷新才能执行</a>]</div>