2013-01-13 35 views
2

我有一個引導模式,有一個窗體,它成功提交併獲得成功消息,假設我想添加一個鏈接到相同的模式來加載相同的窗體目前開放模式。加載第一個提交後相同的twitter引導模式

當我點擊鏈接模式隱藏。

這是我鏈接到模態的鏈接。

<a class="registerBtn" data-toggle="modal" href="#registerModalForm" >Register</a> 

感謝

回答

0

我會處理這個問題的方法是有一個隱藏的DIV表格數據(我們稱之爲formData)是從模態DIV完全分開。例如:

<div id="formData" class="hide"> 
    <form href="#" action="post"> 
     Name: <input id="nameText" type="text"/> 
     <a href="#" id="mySubmit" class="btn btn-primary">Submit</a> 
    </form> 
</div> 

然後創建的事件,以使得當模態顯示,它加載形式數據轉換成模態的主體:

$("#myModal").on("show", function() { 
    // load the modal with content from the div formData 
    $(".modal-body", this).html($("#formData").html()); 
}); 

於是最後,事件添加到按鈕重新加載的形式(這裏的按鈕一個id = myReload:。

$("body").on('click', 'a.btn-primary', function() { 
     // A button with the class btn-primary was clicked. If this is the reload button 
     // reload the HTML into the modal 
     if ($(this).attr("id") == "myReload") { 
       $(this).parent().html($("#formData").html()); 
     } 
}); 

JSFiddle here(忽略提交按鈕的代碼,這只是模擬表單提交)

+0

準確地說,我想要的概念,我正在努力實施它在我的情況。但爲什麼在我的情況下,當我點擊提交頁面重新加載和模態隱藏,但表單提交。 –

+0

如果您不希望頁面重新加載,則必須使用ajax調用提交表單,並在ajax調用的成功回調中填充模式的主體。這是一個很好的例子:http://www.jstiles.com/Blog/How-To-Submit-a-Form-with-jQuery-and-AJAX – mccannf

+0

但我很驚訝爲什麼會發生這種情況時,我通過插入表單jQuery –

相關問題