2013-01-15 87 views
0

我使用jquery ajax檢索成功的數據,並在bootstraps模式中輸出主題。我想要做的是綁定模式關閉事件,但似乎並不奏效。引導模式關閉

$(document).on('click', 'a#edit-button', function(e) { 
      e.preventDefault();  
      var id = $(e.target).data('id'); 
      var url = 'edit.php?id=' + $(e.target).data('id'); 
      $.ajax({ 
       type: "POST", 
       url: url, 
       success: function(data) 
       { 
        $('<div class="modal" id="myModal">' + data + '</div>').modal(); // show response from the php script. 
       }, 
       error:function(){ 

        alert('Error!'); 

       } 
      } 

); });

$('#myModal.modal').bind('hidden', function() { 
     alert('TEST'); 
     //$('#example.table').dataTable().fnDraw(); 
    }); 
+0

也許嘗試$( '#myModal')上。( '隱藏',函數(){ 警報( '測試'); //$('#example.table')。 dataTable()。fnDraw(); }); – 2013-01-15 10:44:47

+0

感謝您的反饋!嘗試但不會工作 – fefe

+0

啊,模態是動態生成的,所以儘量不要動態生成它,或者使用'live'而不是'on' – 2013-01-15 10:53:29

回答

0
$('#modelID') 
    .on('hide.bs.modal', function() { 
     console.log('hide'); 
    }) 
    .on('hidden.bs.modal', function() { 
     console.log('hidden'); 
    }) 
    .on('show.bs.modal', function() { 
     console.log('show'); 
    }) 
    .on('shown.bs.modal', function() { 
     console.log('shown'); 
    }); 
相關問題