js限制文本框只能输入数字(兼容IE和火狐)

<input type="text" onKeyPress="return inputNum(event);" > 
 
function inputNum(event){  
    //火狐使用event.which获取键盘按键值,IE使用window.event.keyCode获取键盘按键值
    var e = event.which?event.which:window.event.keyCode;
    if(e >= 48 &&  e<= 57){
        return true;    
    }else{
        return false;
    }  
}  


猜你喜欢

转载自blog.csdn.net/Julylyna/article/details/80183410