jQuery .load()函数不能与DataTables一起使用?

问题描述 投票:1回答:1

我正在尝试将Datatables与外部html表一起使用。下面的代码可以正常工作:

<table id="myTable" class="table table-striped" >  
  <thead>  
    <tr>  
      <th>ENO</th>  
      <th>EMPName</th>  
      <th>Country</th>  
      <th>Salary</th>  
    </tr>  
  </thead>  
  <tbody>  
    <tr>  
      <td>001</td>  
      <td>Anusha</td>  
      <td>India</td>  
      <td>10000</td>  
    </tr>   
  </tbody>  
</table>  

但是,如果我这样做的话:

<div class="container">
  <div id="includedContent"></div>
</div>

使用此作为脚本:

$(function(){
  $("#includedContent").load("bigtableofdata.html");
});

系统不再起作用。我似乎无法弄清楚,我想知道是否需要以某种方式对其进行特殊格式化才能使其正常工作。任何帮助,不胜感激。

jquery html datatables
1个回答
1
投票
您将需要在load()的完整回调中初始化插件>

$("#includedContent").load("bigtableofdata.html", function(){ /// new html exists now $('#myTable').DataTable(/*options*/) });

© www.soinside.com 2019 - 2024. All rights reserved.