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",@onsubmit="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" onclick="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}}

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM