簡體   English   中英

頁面加載后刪除ajax加載器映像

[英]Remove ajax loader image after page load

我有一個帶有必填字段的表單,當單擊“提交”按鈕時,出現一個加載器圖像。 這具有代碼:

jQuery(document).ready(function($){
    {
        $.getElementById('form').onsubmit = function () {
            $.getElementById('submit').style.display = 'block';
            $.getElementById('loading2').style.display = 'block';
        };
    }(document));
)};

HTML:

<input type="submit" class="button alt"  onclick="$(\'#loading\').show();" id="place_order"/>.

我遇到的問題是,當必填字段不是字段並且單擊了提交按鈕時,出現了加載程序圖像,並且當顯示必填字段錯誤時,仍然顯示加載程序圖像。

如何防止其顯示?

我不喜歡您這樣使用jquery,

我自己要做的是驗證表單並使用jquery自己發布結果,這意味着可以更好地控制所有內容,因此我的代碼將如下所示:

 $('#formBtn').click(function(){ $("#loading").fadeIn(); //use some validation here and let code go to other line if validation passed $.post("/signup",$('#form').serialize(),function(){ //other action like redirecting to homepage or showing a message }).fail(function(){ //to show a message that submit was failed }).always(function(){ $("#loading").fadeOut(); }); }) 

使用jQuery post或get提交表單,然后在回調中驗證您的響應,然后在驗證完成后使用.hide()。

您嘗試使用jQuery BlockUI插件可能會更容易。

jQuery BlockUI插件

當您想要阻止時,可以使用

$.blockUI();

當您想解除封鎖時,可以使用

$.unblockUI();

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM