<html><head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
<meta name="GENERATOR" content="Microsoft FrontPage 4.0">
<meta name="ProgId" content="FrontPage.Editor.Document">
<title>New Page 1</title>
</head><body>
<input type="text" name="T1" id="T1" size="5" onkeyup="if(/^\d+(\.)?(\d+)?$/.test(this.value)==false){alert('请输入数字!');this.value='';}" class="input">
</body></html>

解决方案 »

  1.   

    //函数名:fucCheckNUM
    //功能介绍:检查是否为数字
    //参数说明:要检查的数字
    //返回值:1为是数字,0为不是数字
    function fucCheckNUM(NUM)
    {
     var i,j,strTemp;
     strTemp="0123456789";
     if ( NUM.length== 0)
      return 0
     for (i=0;i<NUM.length;i++)
     {
      j=strTemp.indexOf(NUM.charAt(i)); 
      if (j==-1)
      {
      //说明有字符不是数字
       return 0;
      }
     }
     //说明是数字
     return 1;
    }
      

  2.   

    <body><form>price:<input id=bb><input type=submit onclick="if(isNaN(bb.value)) {alert('not a number');return false;} "></form>
    </body>