function checkaction(){
 if(document.form1.title.value==""){
alert("标题不能为空!");
document.form1.title.focus();
return ;
}
    
if(editor.getHTML()==""){
alert("内容不能为空!");
return ;
}
document.form1.btok.disabled=true;
form1.action="article_save.jsp";
form1.submit();
      }
           <form action="" method="post" name="form1">   
<table width="100%" height="29" border="0" cellpadding="0" cellspacing="0"> 
  <tr>
  <td align="center"><label> 
     <input type="button" name="btok" value="确  定" onclick="return checkaction()" />
              <input type="button" name="back" value="返  回" onclick="javascript:history.back()"/>
   </td>
  </tr>
 </table>
</form>这样的话,会提交2次,而且内容完全一致。后在网上找到方法说:            function checkaction(){
 if(document.form1.title.value==""){
alert("标题不能为空!");
document.form1.title.focus();
return ;
}
    
if(editor.getHTML()==""){
alert("内容不能为空!");
return ;
}
document.form1.btok.disabled=true;
form1.action="article_save.jsp";
      }            <form action="" method="post" name="form1" onsubmit=“return checkaction()”>                <input type="submit" name="btok" value="确  定" /> 
            </form>
这样可以控制提交2次,但是,会出现如下问题: 
          控制是否为空的时候,会出现空提交。也就是判断了“标题不能为空”,但是页码会重新刷一下。把原来页码上的内容清空。只要有一个为空的,就算原来内容不为空,还是刷新页面。没有了。
各位,请不惜赐教。谢谢
      

解决方案 »

  1.   

    内容提交2次啊。
     就是提交了submit ,好像eWebEditor.jsp里面还要提交2次。
    function checkaction(){
             if(document.form1.title.value==""){
                alert("标题不能为空!");
                document.form1.title.focus();
                return ;
            }
                
            if(editor.getHTML()==""){
                alert("内容不能为空!");
                return ;
            }    
                document.form1.btok.disabled=true;
                form1.action="article_save.jsp";
             }            <form action="" method="post" name="form1" onsubmit=“return checkaction()”>                   <input type="submit" name="btok" value="确  定" /> 
                </form>
    这样把 "type = submit" 就可以解决提交2次。但是就会出现我说的 经过js验证时,只要一个为空的,页面就里面刷新一遍。比如,标题、作者、内容都不允许为空,现在要提交,(作者、内容都不为空,标题为空),那么点击提交,会提示“标题”不能为空。但是此时界面会里面刷新一下,把原来的作者、内容里面的信息都个刷新没了。
      

  2.   

    首先给你纠正一个错误啊,你的JavaScript方法,你在判断如果为空的时候,你就让return false,那样的话好像才可以的。
    如果你直接写return的话在Java代码里是可以让程序停止的,而JavaScript中程序是停止不了的。把表单的提交写在你最后一个判断的else里,那样肯定出不了你这样的错误。来分啊。呵呵
      

  3.   

    你不是想如果有时空的话就不提交么,我给你改看看啊:
      function checkaction(){
             if(document.form1.title.value==""){
                alert("标题不能为空!");
                document.form1.title.focus();
                return false;
            }
                
            if(editor.getHTML()==""){
                alert("内容不能为空!");
                return false;
            } 
             esle   
                 {
                   document.form1.btok.disabled=true;
                   form1.action="article_save.jsp";
                   form1.submit();
                 }
             }把你的JavaScript改成这样就音高好了
      

  4.   

    还没好,问题好像是eWebEditor.jsp 这个问题,只要引用了这个文本编辑器,再提交的时候,就会提交2次,和上面的js也没有多的关系,我都试过了。问题还没解决。
      

  5.   

    这个问题我今天解决了。
     
        问题就是再 eWebEditor.jsp 加一句 在文件中增加一行
        <input type="hidden" ID="ModeEdit" value="">;
         去下载eWebEditor V2.80修正版(asp版本),
        打开Include目录下的editor.js,
        替换jsp版本中的editor.js,
        然后,验证的时候如下验证就可以。。
     这个要多谢:http://blog.csdn.net/jewelry008/archive/2007/11/20/1894992.aspx 博客写的。
     function checkaction(){
             if(document.form1.title.value==""){
                alert("标题不能为空!");
                document.form1.title.focus();
                return ;
            }
                
            if(editor.getHTML()==""){
                alert("内容不能为空!");
                return ;
            }    
                document.form1.btok.disabled=true;
                form1.action="article_save.jsp";
                form1.submit();
             }
               <form action="" method="post" name="form1">      
        <table width="100%" height="29" border="0" cellpadding="0" cellspacing="0"> 
          <tr>
          <td align="center"><label> 
             <input type="button" name="btok" value="确  定" onclick="return checkaction()" />
                  <input type="button" name="back" value="返  回" onclick="javascript:history.back()"/>
           </td>
          </tr>
         </table>
        </form>
      

  6.   

    为什么我的会提示 ModeEdit 未定义呢。求 赐教