<table align="center"><tr><td>操作流程:1、填写资料;2、上传附件</td></tr></table>
<form action="<%=basePath %>xfgl/console/filemanage/docall/addDocall.do?state=add" method="post" onsubmit="return checkDoc(this)">
<table align="center" cellspacing="0" border="1" bordercolor="#EAEAEA" class="inputTab">
<thead class="listTh"><tr><th colspan="4">信息增加</th></tr></thead>
<tbody class="listTb">
<tr>
<td width="15%" align="right">文档名称:</td>
<td colspan="3"><input name="name" type="text" size="22" /> *</td>
</tr>
<tr>
<td align="right">上传日期:</td>
<td><input name="date" type="text" value="点击" onclick="HS_setDate(this);" size="22" maxlength="60" readonly="readonly" /> *</td>
</tr>
<tr>
<td align="right">上传人:</td>
<td><input name="person" type="text" size="22" /> *</td>
</tr>
<tr>
<td height="150" align="right">文档简述:</td>
<td colspan="3"><textarea name="depict" cols="66" rows="8"></textarea></td>
</tr>
<tr><td colspan="2"><input type="hidden" name="hasAtt" value="0" /></td></tr>
</tbody>
<tfoot>
<tr><td align="center" colspan="2">
<input name="submit1" type="button" value="有附件上传" onclick="formSubmit(this.form, 1);" />
<input name="submit0" type="button" value="无附件上传" onclick="formSubmit(this.form, 0);"/>
<input name="cancel" type="button" value="取消" onclick="javascript:history.go(-1)" />
</td></tr>
</tfoot>
</table>
</form>各位可以看到验证时是调用onsubmit="return checkDoc(this)",但总是不起作用。我的理解是onsubmit只对type="submit"的按钮起作用,对type="button"则不行。那对本问中type="button"的验证要怎样才行?我也试过把type="button"改成type="submit",但弹出警告对话框后还是会跳转到其他页面。路径和函数是没问题的。
<form action="<%=basePath %>xfgl/console/filemanage/docall/addDocall.do?state=add" method="post" onsubmit="return checkDoc(this)">
<table align="center" cellspacing="0" border="1" bordercolor="#EAEAEA" class="inputTab">
<thead class="listTh"><tr><th colspan="4">信息增加</th></tr></thead>
<tbody class="listTb">
<tr>
<td width="15%" align="right">文档名称:</td>
<td colspan="3"><input name="name" type="text" size="22" /> *</td>
</tr>
<tr>
<td align="right">上传日期:</td>
<td><input name="date" type="text" value="点击" onclick="HS_setDate(this);" size="22" maxlength="60" readonly="readonly" /> *</td>
</tr>
<tr>
<td align="right">上传人:</td>
<td><input name="person" type="text" size="22" /> *</td>
</tr>
<tr>
<td height="150" align="right">文档简述:</td>
<td colspan="3"><textarea name="depict" cols="66" rows="8"></textarea></td>
</tr>
<tr><td colspan="2"><input type="hidden" name="hasAtt" value="0" /></td></tr>
</tbody>
<tfoot>
<tr><td align="center" colspan="2">
<input name="submit1" type="button" value="有附件上传" onclick="formSubmit(this.form, 1);" />
<input name="submit0" type="button" value="无附件上传" onclick="formSubmit(this.form, 0);"/>
<input name="cancel" type="button" value="取消" onclick="javascript:history.go(-1)" />
</td></tr>
</tfoot>
</table>
</form>各位可以看到验证时是调用onsubmit="return checkDoc(this)",但总是不起作用。我的理解是onsubmit只对type="submit"的按钮起作用,对type="button"则不行。那对本问中type="button"的验证要怎样才行?我也试过把type="button"改成type="submit",但弹出警告对话框后还是会跳转到其他页面。路径和函数是没问题的。
function formSubmit() {if(验证成功){
document.forms[0].action = "";
document.forms[0].submit();
} else {
alert("验证不成功!");
}
}
onsubmit不是只对submit起作用 而是当表单提交的时候起作用,在提交前调用 该方法里如果返回true或者无返回值则提交,false不提交,是不是你没有返回值
如果用 button,可以在onclick事件中执行验证,完成后手动提交表单
function formSubmit() {
document.forms[0].action = "";
document.forms[0].submit();
}
fun(var p1, var p2){
//add code here if(formSubmit(p1, p2))
p1.submit();
}onclick="fun(this.form, 1)"
//form定一个名字name = form
//全部按钮onclick
function action(){
if(成功){
formSubmit($('form'), 0); }else{
formSubmit($('form'), 1); }
}
document.form[0].action=""
document.form[0].submit();