文本框只能輸入數(shù)字的實(shí)現(xiàn)方法(兼容IE火狐)

字號(hào):


    下面小編就為大家?guī)硪黄谋究蛑荒茌斎霐?shù)字的實(shí)現(xiàn)方法(兼容IE火狐)。小編覺得挺不錯(cuò)的,現(xiàn)在就分享給大家,也給大家做個(gè)參考。
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    <html xmlns="http://www.w3.org/1999/xhtml">
    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <title>無標(biāo)題文檔</title>
    <script language="javascript" type="text/javascript"> 
    //注意:火狐使用event時(shí), 
    function inputNum(evt){ 
      //火狐使用evt.which獲取鍵盤按鍵值,IE使用window.event.keyCode獲取鍵盤按鍵值
      var ev = evt.which?evt.which:window.event.keyCode;
      if(ev>=48&&ev<=57){
        return true;  
      }else{
        return false;
      } 
    }  
    </script>  
    </head>
    <body>
      <input type="text" onKeyPress="return inputNum(event);" > 
    </body>
    </html>
    以上就是小編為大家?guī)淼奈谋究蛑荒茌斎霐?shù)字的實(shí)現(xiàn)方法(兼容IE火狐)全部?jī)?nèi)容了