2016-02-29 51 views
2

我正在使用它來顯示我的模態。javascript中的html模式

<script> 
     Mousetrap.bind('j e f f r e y enter', function() { 
      $('#myModal').modal('show') 
     });    
</script> 

通常使用按鈕。

<a data-toggle="modal" class="btn btn-info" href="remote.html" data-target="#myModal">Click me !</a> 

有沒有什麼辦法讓從另一個html頁面的模式,並使用JavaScript調用它呢?

+0

也許你可以使用Ajax來獲取HTML並呈現在當前的DOM? – rrw

+0

看看這個:http://stackoverflow.com/questions/23801446/bootstrap-modal-from-another-page – chackerian

回答

0

您可以發送Ajax請求以獲取模態的HTML代碼,然後將其附加到文檔。

<script> 
    var $modal = undefined; 
    Mousetrap.bind('j e f f r e y enter', function() { 
     if($modal === undefined) 
     { 
      $.get('path/to/modal.html', function(data)){ 
       if($modal === undefined) 
       { 
         $modal = $(data); 
         $('body').append($modal); 
       } 
       $modal.modal('show'); 
      }); 
      return; 
     } 
     $modal.modal('show') 
    });    
</script> 
+0

謝謝!試過這個,但是,輸入我的捕鼠器綁定後沒有任何反應 –