在提交按钮上单击我需要检查验证是否返回true
。我需要提交表格。但是当它返回false
时,表单也会被提交并调用事件SaveProjects()
。如何在CheckValidation()
返回false
时阻止表单提交?
<script type="text/javascript>
function CheckValidation()
{
alert();
return false;
}
</script>
@using (@Ajax.BeginForm("SaveProjects", "Projects", null, new AjaxOptions { OnSuccess = "OnSuccessProject", HttpMethod = "post" }, new { id = "ProjectsForm" }))
{ <div class="outerBox" id="divProjectCreate">
@Html.Partial("../Projects/_CreateOrEdit", Model)
<div class="row centerAlign">
<input type="submit" value="Save" id="btnSaveProjects" onclick="CheckValidation()"/>
<input type="button" value="Cancel" id="btnCancel" />
</div>
</div>
}
答案 0 :(得分:1)
你可以做到
$('#target').submit(function() {
alert('Handler for .submit() called.');
return CheckValidation();
});