function goto_page(e){ var keynumber; //键盘ASCII码 if(window.event){ //浏览器为IE keynumber = e.keyCode; } if(e.which){ //浏览器为Firefox、Opera keynumber = e.which; } if(keynumber < 48 || keynumber > 105 || (keynumber > 57 && keynumber < 96)){ document.getElementById("pageno").value="1"; } }
<input type="text" id="pageno" onkeydown="goto_page(e)" onkeyup="goto_page(e)"></input>