<script language="javascript">
function checkNum(str){
if(!/\D/.test(str))
eval(form+".submit()");
else
alert("请输入数字!");
}
</script>

解决方案 »

  1.   

    以上都不对唉,代吗给出,你们自已试试:
    <html>
    <head>
    <title>无标题文档</title>
    <meta http-equiv="Content-Type" content="text/html; charset=gb2312">
    <script language="javascript">
    function checkNum(str){
    if(!/\D/.test(str))
    eval(form+".submit()");
    else
    alert("请输入数字!");
    }
    </script></head><body bgcolor="#FFFFFF" text="#000000">
    <form name=form1 method=post action="post.asp">
    <input name= text1 type=text>
    <input type=button value=button1 name=button1 onclick="javascript:checkNum(form1.text1.value)">
    </form><form name=form2 method=post action="post.asp">
    <input name= text2 type=text >
    <input type=button value=submit onclick="javascript:checkNum(form2.text2.value)">
    </form></body>
    </html>
      

  2.   

    <script language="javascript">
    function checkNum(str,form){
    if(!/\D/.test(str))
    form.submit();
    else
    alert("请输入数字!");
    }
    </script></head><body bgcolor="#FFFFFF" text="#000000">
    <form name=form1 method=post action="post.asp">
    <input name= text1 type=text>
    <input type=button value=button1 name=button1 onclick="javascript:checkNum(this.form.text1.value,this.form)">
    </form><form name=form2 method=post action="post.asp">
    <input name= text2 type=text >
    <input type=button value=submit onclick="javascript:checkNum(this.form.text2.value.this.form)">
    </form>
      

  3.   

    xuzuning(唠叨) 的方法,第一个添数字可以提交,但再在第二个框里添数字就会出现脚本错误!
    请问那位高手可以解决啊!!!
      

  4.   

    再加一个参数吧!能解决问题就行,别太强求……<html>
    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=gb2312">
    <title></title>
    </head>
    <body>
    <form action="" method="get" name="form1">
    <input name="noname" type="text" onBlur="checkNum(this.value,'form1')">
    </form>
    </body>
    </html>
    <script language="javascript">
    function checkNum(str,formname)
    {
        if(!/\D/.test(str)){
       (eval(formname)).submit();
    }
    else{
        alert("请输入数字!");
    }
    }
    </script>
      

  5.   

    <script>
    function checkNum(str,form){
    if(!/\D/.test(str))
    form.submit();
    else
    alert("请输入数字!");
    }
    </script><form name=ex method=post action="">
    <input name=text1 type=text size="20">
    <input type=button value=button1 name=button1 onclick="checkNum(this.form.text1.value,this.form)">
    </form><form name=qq method=post action="">
    <input name=text2 type=text size="20" >
    <input type=button value=button2 name=button2 onclick="checkNum(this.form.text2.value,this.form)">
    </form>
      

  6.   

    噢,手快了
    ....
    <input type=button value=submit onclick="javascript:checkNum(this.form.text2.value,this.form)">
    </form>
    是,不是.