doubi5127 2017-03-14 19:33
浏览 1007

JS文件在innerhtml中不起作用

I have a div with dynamically content.

<div id='data'></div>

inside div is a table with class.

<table class="table table-hover table-expandable table-striped">

'table-expandable' execute with this js file

<script src="<?php echo base_url();?>assets_d/expand/bootstrap-table-expandable.js"></script>

when page refresh this work fine, but when I load dynamically div with ajax

 $(document.getElementById(data)).html(dynamiclyTable);

script on js file does not work, this is script on js file

(function ($) {
$(function () {
    var i=0;
    $('.table-expandable').each(function () {
        var table = $(this);
        i++;
        alert(i);
        table.children('thead').children('tr').append('<th></th>');
        table.children('tbody').children('tr').filter(':even').each(function () {
            var element = $(this);
            element.append('<td><div class="table-expandable-arrow"></div></td>');
        });
        table.children('tbody').children('tr').filter(':odd').hide();
        table.children('tbody').children('tr').filter(':even').on('click',function () {
               var element = $(this);
                element.next('tr').toggle('slow');
                element.find(".table-expandable-arrow").toggleClass("up");
        });

    }); 
});
})(jQuery); 

Is there a way to call js file after div load dynamically content ? Thanks

  • 写回答

0条回答 默认 最新

    报告相同问题?

    悬赏问题

    • ¥15 nslt的可用模型,或者其他可以进行推理的现有模型
    • ¥15 arduino上连sim900a实现连接mqtt服务器
    • ¥15 vncviewer7.0安装后如何正确注册License许可证,激活使用
    • ¥15 phython如何实现以下功能?查找同一用户名的消费金额合并2
    • ¥66 关于人体营养与饮食规划的线性规划模型
    • ¥15 基于深度学习的快递面单识别系统
    • ¥15 Multisim仿真设计地铁到站提醒电路
    • ¥15 怎么用一个500W电源给5台60W的电脑供电
    • ¥15 请推荐一个轻量级规则引擎,配合流程引擎使用,规则引擎负责判断出符合规则的流程引擎模板id
    • ¥15 Excel表只有年月怎么计算年龄