event.keyCode不是字符串,要用13
if (window.event.keyCode==13)

解决方案 »

  1.   

    <script language=javascript>
    function bNumber(this){
    var moblen=[this].value.length
    var mob=[this].value
    var i,mobstr=true
    for (i=0;i<=moblen;i++)
    {
    if((mob.charAt(i)<"0")||(mob.charAt(i)>"9"))
    {
    mobstr=false
    break
    }
    }
    return mobstr
    }  
    function SERV_NBRKeyPress(this){
        if (window.event.keyCode==13){//回车键
          if (!bNumber(this.value)){
            alert("输入的字符含有非数字信息!");
            this.focus();
            this.select();
            return false;
          }}}
    </script>
    <table border="0" width=100% class=TableStyle cellpadding="0" cellspacing="0">
              <tr> 
                <td align=right>手机号码:</td>
                <td align=left> 
                  <input type='TEXT' name="SERV_NBR" maxlength="11" onKeyPress="SERV_NBRKeyPress(this);" value="">
                </td>
        </tr>
      </table>完整代码如上,另外,如何读出SERV_NBR的值呢?
      

  2.   

    改好了,测试通过。你用错了函数,把bNumber改为isNaN即可。
    <script language=javascript>
      function SERV_NBRKeyPress(that){
        if (window.event.keyCode==13){//回车键
          if (isNaN(that.value)){
            alert("输入的字符含有非数字信息!");
            that.focus();
            that.select();
            return false;
          }}}
    </script>
    <table border="0" width=100% class=TableStyle cellpadding="0" cellspacing="0">
              <tr> 
                <td align=right>手机号码:</td>
                <td align=left> 
                  <input type='TEXT' name="SERV_NBR" maxlength="11" onKeyPress="SERV_NBRKeyPress(this);" value="">
                </td>
        </tr>
      </table>