JS强制输入数字


<script type="text/javascript" src="jquery-1.7.1.js"></script>
<script>
isNumber = function (e) {  
    if ($.browser.msie) {  
        if ( ((event.keyCode > 47) && (event.keyCode < 58)) ||  
              (event.keyCode == 8) ) {  
            return true;  
        } else {  
            return false;  
        }  
    } else {  
        if ( ((e.which > 47) && (e.which < 58)) ||  
              (e.which == 8) ) {  
            return true;  
        } else {  
            return false;  
        }  
    }  
}

function alertaaa(){
	var aaaaa = $('#222').val();
	alert(aaaaa);
	
	alert(Number(aaaaa)*10);
}

</script>

<input id="123" type="text" onkeypress="javascript:return isNumber(event);"/> 
<input type="text" id="222" onKeyUp="this.value=this.value.replace(/\D/g,'')" />
<input type="button" onClick="alertaaa();" value="aaaa"/>


你可能感兴趣的:(JavaScript,function,input,button)