当我点击使用Codeigner打开Bootstarp Modal时,如何调用javascript函数Serverytim


How to call javascript function erverytime when i click to open Bootstarp Modal using Codeigniter?

我想在单击链接并打开Bootstarp Modal时调用javascript函数。

当第一次Bootstarp Modal加载时,函数被调用,但当我关闭Bootstrap Modal并再次单击相同的链接并打开相同的Bootstrap Mode时,函数就不会被调用。

我想每次打开Bootstrap Modal时都调用函数。

引导调用功能:

$(document).on("click", "#update_project_image_modal", function() {
    var cid = $(this).data('id');
     console.log(cid);
     $.ajax({
         url: '<?=$this->config->base_url()?>admin_panel/update_project_images_popup',
         type: 'post',
         data: 'project_id=' + cid
     }).done(function(data) {
         jQuery('#categoryModal .modal-content').html(data);
         $('#categoryModal').modal({
            "backdrop" : "static"
        });
     });
 });

Bootstrap模式加载中的函数调用:

  $(document).ready(function($) {
    console.log('ready');
listFilesOnServer();
});

HTML表格(点击链接打开Bootstarp Modal):

<table id="table3" class="display table table-bordered table-striped table-hover">
    <thead>
        <tr>
            <th> Name</th>
            <th> Location</th>
            <th>Action</th>
        </tr>
    </thead>
    <tbody>
        <tr>
            <td>jkhjk</td>
            <td>kjhjk</td>
            <td><a href="javascript:void(0)" id="update_project_image_modal" data-id="225"> Images</a>
            </td>
        </tr>
    </tbody>
</table>

Bootstrap有一个事件,当调用模态时会触发:

显示.bs.模式

调用show实例方法时,此事件会立即激发。如果是由单击引起的,则单击的元素可用作事件的relatedTarget属性。

在你的情况下,你会这样使用它:

$('#categoryModal').on('show.bs.modal',function(evt){
    listFilesOnServer();
});