Jquery.validate 与 onsubmit 配合使用问题

function WaitFor() {
    var div = $('<div style="Filter:Alpha(Opacity=50);background-color:#FFE4B5;position:absolute;top:0;left:0;width:100%;height:75%;text-align:center;padding:250px 0 0 0;"><div style="width:280px;border:solid 1px #000;padding:20px 0 20px 0;color:#000;font-weight:bold;">wait for processing......</div></div>');
    $('body').append(div);
}

function AskContinue() {
    if (confirm("Are you sure you want to do it?")) {
                   $("form").submit();
    }
}

@using (Html.BeginForm("ForUpload", "CSOT", FormMethod.Post, new { @enctype = "multipart/form-data",@οnsubmit="WaitFor()"}))
{
    <div>
        <fieldset>
            <legend>CSOT Upload File</legend>
            <div class="editor-label">
            TXT File
            </div>
            <div class="editor-label">
            @Html.TextBoxFor(m=>m.TXTFile, new { @type = "file", @style = "width:95%;" })
            <br/>@Html.ValidationMessageFor(m => m.TXTFile)
            </div>

           <div class="editor-label">
            <input type="button" style = "width:200px" οnclick="AskContinue()" value="Submit"/>
            </div>       

         </fieldset>
     </div>
}

 

在MVC3中,如果一起使用 Html.ValidationMessageFor 和 onsubmit 时,

其执行顺序是 onclick-if(true)-{$("form").submit()-validate-onsubmit-post}

 

问题:这个时候如果验证不通过,WaitFor 将覆盖在上面,无法编辑。

 

则要对AskContinue作以下修改:

 

if($("form").valid()){

             $("form").submit();

}

其执行顺序是 onclick-if(true)-{validate-if(true)-{$("form").submit()-onsubmit-post}}

 

转载于:https://www.cnblogs.com/yipeng-yu/archive/2012/05/18/2507335.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值