我想在单击链接并打开 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 有一个事件,当模态被调用时会触发:
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/