如下代码,要求当点击不同意按钮时不会弹出"不能为空!"直接跳到另一页面,
         (可以获得的q参数与no参数的值) 
          要求当点击同意按钮时弹出"不能为空!" 
        
<html> 
<head> <title> ere </title> </head> 
<body> 
<form   method="post"   action="ok.jsp"   onsubmit="return   Checkok();"> 
<table> 
<tr> <td> 
<INPUT   TYPE="text"   NAME="q"   value="333"> 
<INPUT   TYPE="text"   NAME="qw"   value=""> 
</td> </tr> 
<tr> <td> 
<input   type='submit'   name='no'   value='   不同意   '> 
<input   type='submit'   name='yes'   value='   同意   '> 
</td> </tr> 
<table> 
</form> 
</body> 
</html> 
<SCRIPT   LANGUAGE="JavaScript"> 
function   Checkok() 

if(document.all("qw").value   ==   "") 

alert("不能为空!"); 
document.all("qw").focus(); 
return   false; 
}else 
{ return   true;   } 

</Script> 
ok.jsp
<%  
   String qw=request.getParameter("qw");
   String q=request.getParameter("q");
   String no=request.getParameter("no");
   String yes=request.getParameter("yes");
   out.print(no);
   out.print(yes);
%>

解决方案 »

  1.   

    你不要设置成提交按钮啊,事件也不要onsubmit.
    应该是普通按钮,事件是onclick调用js,在js函数里面用 表单名+submit();提交表单就ok
      

  2.   

    看红色部分<html>   
    <head>   <title>   ere   </title>   </head>   
    <body>   
    <form       method="post"       action="ok.jsp"       onsubmit="return       Checkok();">   
    <table>   
    <tr>   <td>   
    <INPUT       TYPE="text"       NAME="q"       value="333">   
    <INPUT       TYPE="text"       NAME="qw"       value="">   
    </td>   </tr>   
    <tr>   <td>   
    <input name="no" type="button"  onclick="http://不同意对应的网址"/> 
    <input       type='submit'       name='yes'       value='       同意       '>   
    </td>   </tr>   
    <table>   
    </form>   
    </body>   
    </html>   
    <SCRIPT       LANGUAGE="JavaScript">   
    function       Checkok()   
    {   
    if(document.all("qw").value       ==       "")   
    {   
    alert("不能为空!");   
    document.all("qw").focus();   
    return       false;   
    }else   
    {   return       true;       }   
    }   
    </Script>   
    ok.jsp 
    <%     
          String   qw=request.getParameter("qw"); 
          String   q=request.getParameter("q"); 
          String   no=request.getParameter("no"); 
          String   yes=request.getParameter("yes"); 
          out.print(no); 
          out.print(yes); 
    %> 
      

  3.   

    <html>
    <head>   <title>   ere   </title>   </head>
    <body>
    <form  method="post"  action="ok.jsp"  onsubmit="return  Checkok();">
    <table>
    <tr>   <td>
    <INPUT  TYPE="text"  NAME="q"  value="333">
    <INPUT  TYPE="text"  NAME="qw"  value="">
    </td>   </tr>
    <tr>   <td>
    <input  type='button' onclick="gotoOtherPage()"  name='no'  value='  不同意  '>
    <input  type='submit'  name='yes'  value='  同意  '>
    </td>   </tr>
    <table>
    </form>
    </body>
    </html>
    <SCRIPT  LANGUAGE="JavaScript">
    function  Checkok()
    {
    if(document.all("qw").value  ==  "")
    {
    alert("不能为空!");
    document.all("qw").focus();
    return  false;
    }else
    {   return  true;  }
    }
    function gotoOtherPage(){
      ... 写你的代码吧!
    }
    </Script>
      

  4.   

    <input type='submit' name='no'  value='不同意'  onsubmit="return  Checkok();"  />
    注意上面的红色部分<input>的结束的"/"都忘记加了   
       
      

  5.   

    input可以不用写结束标记的哦
      

  6.   

    通过对js函数传参来确定按的哪个按钮<html>
    <head>
    <title>ere</title>
    <SCRIPT LANGUAGE="JavaScript">   
        function Checkok(inputName) {   
            if(inputName=='no') return true;
            if(inputName=='yes') {
            if(document.all("qw").value == "") {   
                alert("不能为空!");   
                document.all("qw").focus();   
                return false;   
            } else {   
                return true;       
            }   
            }
        }   
    </Script>
    </head>
    <body>
    <form method="post" action="Ok.jsp">
    <table>
    <tr>
    <td><INPUT TYPE="text" NAME="q" value="333"> <INPUT
    TYPE="text" NAME="qw" value=""></td>
    </tr>
    <tr>
    <td><input type='submit' name='no' value='Agree' onclick=Checkok('no')>
    <input type='submit' name='yes' value='Disagree' onclick=Checkok('yes')>
    </td>
    </tr>
    </table>
    </form>
    </body>
    </html>