2012-10-19 64 views
0

我將AJAX表單放入引導模式中。表單成功提交後,我想顯示一條成功消息,然後隱藏模式。在執行jQuery動作之前暫停

我首先將成功消息設置爲msg,然後用消息替換表單,最後,我隱藏下面三行中的模態。

var msg = '<div class="alert alert-success" id="' + $(replace_selector).attr('id') + '">Feedback Submitted</div>' 
$(replace_selector).replaceWith(msg); 
$el_parent.modal('hide'); 

如何在第二行和第三行代碼之間創建延遲?我試過delay,但無法正常工作。

回答

1

試試這個:

$(replace_selector).replaceWith(msg); 
    setTimeout(function(){ 
     $el_parent.modal('hide'); 
    }, 3000);