javascript - 每次使用 Codeigniter 单击打开 Bootstrap Modal 时如何调用 javascript 函数?

标签 javascript php jquery twitter-bootstrap codeigniter

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

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

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

Bootstrap 调用函数:

$(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 有一个事件,当模态被调用时会触发:

show.bs.modal

This event fires immediately when the show instance method is called. If caused by a click, the clicked element is available as the relatedTarget property of the event.

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

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

关于javascript - 每次使用 Codeigniter 单击打开 Bootstrap Modal 时如何调用 javascript 函数?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37048526/

相关文章:

php - 特定 PC 上的 WAMP for php 中出现许多错误

php - 如何计算单行中的字段值?

MYSQL 中的 PHP 变量使用 PDO 选择

javascript - 使用 jQuery 解析 html 代码

javascript - NS_ERROR_FAILURE : Failure in Firefox

javascript - 无法使用 axios 发送带 header 的 get 请求

javascript - JQuery/JavaScript : check if var exists

javascript - 在 JS 中抓取 html 表单数据

Javascript,当颜色改变时改变CSS背景图像

javascript - Object.create 在数组属性上的奇怪行为