日期:2014-05-17  浏览次数:20619 次

今有一个版本的eWebEditor飞鱼版本。其中有些问题,想要讨教。
HTML code
   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次,而且内容完全一致。后在网上找到方法说:

 
HTML code
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次,但是,会出现如下问题: 
  控制是否为空的时候,会出现空提交。也就是判断了“标题不能为空”,但是页码会重新刷一下。把原来页码上的内容清空。只要有一个为空的,就算原来内容不为空,还是刷新页面。没有了。
各位,请不惜赐教。谢谢。。。
 

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

来分啊。呵呵
------解决方案--------------------
你不是想如果有时空的话就不提交么,我给你改看看啊:
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改成这样就音高好了

------解决方案--------------------
问题好了么?