簡體   English   中英

加載帶有引導程序模式的ajax頁面,並一次自動啟動該模式

[英]load ajax page with bootstrap modal in it, and auto launch that modal, all at once

我試圖在我的主頁上創建一個按鈕,以從另一個頁面調用模式。

我需要此模式在加載后自動啟動。

我什么都沒找到。 (還是我想念它?!)

我的代碼:

我正在調用此js函數:

<script>
function startb(plc)
{
    $.ajax({
             url: "gb.php?plc="+plc
          }).done(function( data ) {
           $("#large-div").html(data);
          });   

    //the id of the modal in the gb.php code is: "inside-modal"
      $('#inside-modal').modal('show');

}
</script>

<body>

<div id="large-div" name="large-div">

</div>

<button onclick="startb('28')">start plc</button>



</body>

您需要將$()。modal()函數調用放在ajax請求的回調函數中

根據定義,AJAX是異步的,因此

.modal()
調用發生在div實際上用新的HTML內容填充之前。

解:

 $.ajax({ url: "gb.php?plc="+plc }).done(function( data ) { $("#large-div").html(data); $('#inside-modal').modal('show'); }); 

希望能幫助到你

編輯:

@ Dimitris Nastos,沒有看到您的評論-與此答案完全相同。 會發表評論。

暫無
暫無

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

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