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次,但是,会出现如下问题:
控制是否为空的时候,会出现空提交。也就是判断了“标题不能为空”,但是页码会重新刷一下。把原来页码上的内容清空。只要有一个为空的,就算原来内容不为空,还是刷新页面。没有了。
各位,请不惜赐教。谢谢
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次,但是,会出现如下问题:
控制是否为空的时候,会出现空提交。也就是判断了“标题不能为空”,但是页码会重新刷一下。把原来页码上的内容清空。只要有一个为空的,就算原来内容不为空,还是刷新页面。没有了。
各位,请不惜赐教。谢谢
就是提交了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验证时,只要一个为空的,页面就里面刷新一遍。比如,标题、作者、内容都不允许为空,现在要提交,(作者、内容都不为空,标题为空),那么点击提交,会提示“标题”不能为空。但是此时界面会里面刷新一下,把原来的作者、内容里面的信息都个刷新没了。
如果你直接写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改成这样就音高好了
问题就是再 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>