2015-12-23 26 views
0

我有一個主頁面,我正在加載模態對話框,這些對話框以HTML形式存儲在其他部分html頁面中。我在頁面上的不同按鈕點擊動態加載模態到1模式。HTML中的JavaScript引用無法在模態中加載

的部分頁面對我的情態動詞看起來像這樣1頁:

<script type="text/javascript" src="../App/modals.js"></script> 

<div class="modal-header"> 
    <button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">&times;</span></button> 
    <h4 class="modal-title" id="myModalLabel">Specify entity name you wish to create</h4> 
</div> 
<div class="modal-body"> 
    <div class="row"> 
     <form> 
      <div class="col-md-6"> 
       <input type="text" id="txtEntityNameCreate" /> 
      </div> 
      <p class="modal-log"></p> 
     </form> 
    </div> 
</div> 
<div class="modal-footer"> 
    <button type="button" class="btn btn-default" data-dismiss="modal">Close</button> 
    <button type="button" class="btn btn-primary" onclick="AddEntity()">Create Entity</button> 
</div> 

我在頂部,這將是負責復位內對話文本字段中引用的腳本。我也可能將它用於以後的目的。但是,當我從我的主網頁調用像這樣的對話腳本沒有加載到頁面:

<a id="" data-toggle="modal" data-target="#mainModal" 
    href="modals/createmodal.html" 
    data-remote="modals/createmodal.html" 
    onclick="Utilities.SetFocusModal('txtEntityNameCreate')"> 
    <img src="../Images/create.png" /> 
    <h4>Create Entity</h4> 
</a> 

如何加載對話框時,我可以加載modals.js?

謝謝。

+0

指定'href'兩次在鏈接 – thanksd

+0

感謝,只是修改了它 – Natalie

+0

也許嘗試把腳本標籤的主要頁面,而不是 – thanksd

回答

1

當bootstraps模式被遠程加載時,它們不會重新加載dom,因此頁面不會被重新加載到模式中,而只是插入了html,所以您的腳本很可能不會執行,不確定腳本的外觀像但這很可能是問題。 Bootstrap有一個jquery函數用於顯示模態。所以,如果你的腳本正常運行時加載你的HTML通常情況下,當你打開只是你的片段一樣,那麼你也許可以這樣做你的主頁在以下方面:

$('#mainModal').on('shown.bs.modal', function() { 
    //then put your script here 
}); 

也許

$('#mainModal').on('shown.bs.modal', function() { 
    $.getScript('path/to/script.js'); 
}); 

然後當#mainModal顯示時,腳本將執行。

+0

謝謝,這就是我需要:) – Natalie