<div class="htmlarea"> <textarea id="runcode86"> <script> function checkNumber(e,txt) { var key = window.event ? e.keyCode : e.which; var keychar = String.fromCharCode(key); var el = document.getElementById('test'); var msg = document.getElementById('msg'); reg = /\d|\./; var result = reg.test(keychar); if(result) { if(e.keyCode==46) result=!(txt.value.split('.').length>1); else result=!(txt.value.split('.').length>1&&txt.value.split('.')[1].length>1); } if(!result) { el.className = "warn"; msg.innerHTML = "只能输入数字"; return false; } else { el.className = ""; msg.innerHTML = ""; return true; } } </script> <div id="test"> 只能输入数字的文本框<input type="text" name="question.page" onkeypress="return checkNumber(event,this);"> <span id="msg"></span> </div> </textarea><br><input onclick="runEx('runcode86')" type="button" value="运行代码"> <input onclick="doCopy('runcode86')" type="button" value="复制代码"> <input onclick="doSave(runcode86)" type="button" value="保存代码">[Ctrl+A 全选 注:<a href="http://www.jb51.net/article/23421.htm" title="查看具体详情" target="_blank">如需引入外部Js需刷新才能执行</a>]</div>