input输入非数字无效js

<input onkeypress="return IsNum(event)">

function IsNum(e) 
		{
	          var k = window.event ? e.keyCode : e.which;
	          if (((k >= 48) && (k <= 57)) || k == 8 || k == 0) {
	          } else {
	              if (window.event) {
                          //事件返回值为false,此处就是键盘按下操作返回false,相当于没按键盘
	                  window.event.returnValue = false;
	              }
	              else {
	                  e.preventDefault(); //for firefox 
	              }
	          }
	      }

 

你可能感兴趣的:(input输入非数字无效js)