日期:2014-05-16  浏览次数:20345 次

js控制文本框只能输入数字 兼容FF
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN"> 
<HTML> 
<HEAD> 
<TITLE> New Document </TITLE> 
<META NAME="Generator" CONTENT="EditPlus"> 
<META NAME="Author" CONTENT=""> 
<META NAME="Keywords" CONTENT=""> 
<META NAME="Description" CONTENT=""> 
 
<SCRIPT LANGUAGE="JavaScript"> 
<!--   
function keyPress(evt) {    
evt = (evt) ? evt : ((window.event) ? window.event : "");
//兼容IE和Firefox获得keyBoardEvent对象
var keyCode = evt.keyCode ? evt.keyCode : evt.which;
    if ((keyCode < 48 || keyCode > 57)) {  
if (window.event) { //IE
            evt.returnValue = false; 
      } else {  //Firefox
            evt.preventDefault(); //event.returnValue=false 效果相同.
        }
    }  
}  
//--> 
</SCRIPT> 
</HEAD> 
 
<BODY> 
<INPUT TYPE="text" NAME="jliu" style="ime-mode:disabled;" onpaste="return false;" onKeyPress="keyPress(event)"> 
</BODY> 
</HTML>