如何使用jquery在表单验证后设置加载器

时间:2014-09-05 09:12:40

标签: jquery asp.net-mvc

表单代码

<form name="form1" method="post" action="@GlobalVariable.URL/api/fileupload/Profile" enctype="multipart/form-data" class="form-horizontal"> 

...(某些代码)

<button type="submit" id="Test" class="btn btn-primary" value="Submit" />

我的加载程序代码是

<div id="divLoading" style="margin: 0px; padding: 0px; position: fixed; right: 0px;
    top: 0px; width: 100%; height: 100%; background-color: #666666; z-index: 30001;
    opacity: .8; filter: alpha(opacity=70);display:none">
    <p style="position: absolute; top: 30%; left: 45%; color: White;">
        <img src='@Url.Content(" ~/Content/ajax-loader.gif ")' />
    </p>
</div>

如何在表单验证后激活加载程序?

提前致谢

1 个答案:

答案 0 :(得分:0)

以下代码应该有效,

$(".form-horizontal").validate({
    rules: {
        field: {
            required: true
        }
    },
    submitHandler: function(form) {
        $('#divLoading').show();
        form.submit();
   }
});

http://jqueryvalidation.org/validate