2016-01-22 58 views
0

我有引導模態這裏有一個問題,所以在我的應用程序的後端我從SQL拉出來的數據,我所說的JS函數是這樣的:添加數據來引導模式

ScriptManager.RegisterStartupScript(this, this.GetType(), "ShowPopup", 
        "MailLanguageChange('" + Description + "','" + TextResult + "');", true); 

和JS看起來是這樣的:

function MailLanguageChange(Name, Text) { 
     $('#MainContent_NewMailTemplate').modal('show'); 

     document.getElementById("Upper_txtDesc").value = Name; 
     document.getElementById("TextEditorTextArea").innerHTML = Text; 
    } 

所以螢火命中,在此功能突破點,所以我的函數肯定調用的工作,但來這裏的問題,JS正試圖把這些數據應用於到模式,所有元素之前的模態被加載。

但是,當我使用這種模式的多個purpuses ...有反正寫下來,「不要做任何事情,直到顯示模態」?

$('#MainContent_NewMailTemplate').modal('show'); 

正如文檔所述,在實際顯示模態之前,它會返回給調用者......我怎麼能通過這個?

編輯

這是我怎麼也嘗試過

function MailLanguageChange(Name, Text) { 

     $('#MainContent_NewMailTemplate').modal('show'); 

     $("#MainContent_NewMailTemplate").on('shown.bs.modal', function() { 
      document.getElementById("Upper_txtDesc").value = Name; 
      document.getElementById("TextEditorTextArea").innerHTML = Text; 
     }); 
    } 

結論:

隨着使用全局變量的邏輯由@Guruprasad饒 我結束提供只需簡單地使用

$(document).ready(function() { 
    document.getElementById("Upper_txtDesc").value = name; 
    document.getElementById("TextEditorTextArea").innerHTML = text; 
}); 

謝謝

回答

1

使用twitter-bootstrap'sshown.bs.modal方法如下:

$("#yourmodalid").on('shown.bs.modal',function(){ 
    //Do whatever you want here 
}); 

還有其他一些events尋找到關於modal

enter image description here


更新

看到你展示modal第一,然後你要註冊的事件。所以我建議你下面的步驟。

  • 在js頁面頂部聲明2個全局變量。

防爆

var name,text; 
  • 分配他們看重你的function MailLanguageChange內。

防爆

function MailLanguageChange(Name, Text) { 
    name=Name; 
    text=Text; 
    $('#MainContent_NewMailTemplate').modal('show'); 
} 
  • 保持shown.bs.modal事件某處上述function

防爆外

$("#MainContent_NewMailTemplate").on('shown.bs.modal', function() { 
    document.getElementById("Upper_txtDesc").value = name; 
    document.getElementById("TextEditorTextArea").innerHTML = text; 
}); 
+0

我看到的,但由於某種原因,螢火蟲也沒有這麼函數內..這是我的問題 – Veljko89

+0

你能告訴我們您如何使用它,什麼實際情況?你是否通過'ajax'查看包含'modal'負載? –

+0

我編輯的問題,而不是在這裏使用AJAX,只是在我的C#頁面回發後調用JS函數 – Veljko89