页面上写2个button,一个普通button,另一个是submit,submit的这个隐藏。校验函数写在普通button里,普通button click函数中去提交表单。
页面:
<input type="button" value="提交" class="am-btn am-btn-success" onclick="if (!beforeSubmit()) { return false; }" />
<input type="submit" name="action" value="提交" id="tj" class="am-btn am-btn-success" style="display:none" />
JS:
function beforeSubmit() { //alert("111"); var DataVerification = $("#DataVerification").find('option:selected').val(); if (DataVerification == '已开通') { //已开通 的存量数量不校验,比如:进件后修改简称等。 $("#tj").click(); return true; } }
方式2:
@using (Html.BeginForm("Create", "payMerchant", new { area = "PayLog" }, FormMethod.Post, new { id = "payMerchant_cr", @class = "am-form am-form-horizontal", enctype = "multipart/form-data", onsubmit = "return checksubmit()" }))
在BeginForm中增加 , onsubmit = "return checksubmit()"