2017-01-12 31 views
0

我有這樣一個鏈接:JavaScript的jQuery的電話行動之前模態對話框顯示

<a href="javascript:;" data-toggle="modal" data-target="#modal-dialog" class="my_table" > 

我要綁定的jQuery的行動,將之前的模態對話框顯示工作。

$(document).on('click','.my_table',function(){ 
    alert('Execute before!'); 
}) 

但模態對話框仍然可見。首先我會收到警報,然後進行模態對話。如何使對話框等待,直到警報處理爲closed/callback?請不要建議通過JQuery打開對話框,它不適用於當前的CSS/HTML模型。

回答

1

創建JavaScript函數並在元素單擊時調用它。

<a href="#" data-toggle="modal" onclick="callFunc();" class="my_table"></a> 
<script> 
    function callFunc() { 
     alert('Execute before!'); 
     $('#modal-dialog').appendTo('body').modal('show'); 
    } 
</script> 
1

也許你必須處理模式顯示事件:

$(document).ready(function() { 
    $('#myModal').on('shown.bs.modal', function() { 
     alert('Execute before!'); 
    }) 
});