[英]DataTable doesn't work (jQuery)
我制作了一个简单的表格来在DataTable 中显示类似这样的 dataTable 。 问题是我试图以类似的方式做。
首先,我把编码放在下面:
<table id="myTable" class="display" cellspacing="0" width="100%">
<thead>
<tr>
<th>Name</th>
<th>Position</th>
<th>Office</th>
<th>Age</th>
<th>Salary</th>
</tr>
</thead>
<tbody>
<tr>
<td>Tiger Nixon</td>
<td>System Architect</td>
<td>Edinburgh</td>
<td>61</td>
<td>$320,800</td>
</tr>
<tr>
<td>Cedric Kelly</td>
<td>Senior Javascript Developer</td>
<td>Edinburgh</td>
<td>22</td>
<td>$433,060</td>
</tr>
<tr>
<td>Sonya Frost</td>
<td>Software Engineer</td>
<td>Edinburgh</td>
<td>23</td>
<td>$103,600</td>
</tr>
</tbody>
</table>
我不会忘记像这样调用函数:
<script type="text/javascript">
$(document).ready(function(){
$('#myTable').DataTable();
});
</script>
而且我也按照这样的建议调用了外部资源:
<script src="//code.jquery.com/jquery-1.11.1.min.js"></script>
<script src="//cdn.datatables.net/1.10.4/js/jquery.data"></script>
检查此链接Demo在这里您必须正确包含js
<link rel="stylesheet" type="text/css" href="http://ajax.aspnetcdn.com/ajax/jquery.dataTables/1.9.0/css/jquery.dataTables.css">
<link rel="stylesheet" type="text/css" href="http://ajax.aspnetcdn.com/ajax/jquery.dataTables/1.9.0/css/jquery.dataTables_themeroller.css">
<script type="text/javascript" charset="utf8" src="http://ajax.aspnetcdn.com/ajax/jQuery/jquery-1.7.1.min.js"></script>
<script type="text/javascript" charset="utf8" src="http://ajax.aspnetcdn.com/ajax/jquery.dataTables/1.9.0/jquery.dataTables.min.js"></script>
我花了几个小时来解决这个问题,结果发现我缺少搜索工作所需的标签:
<thead></thead>
和
<tbody></tbody>
从链接的开头删除//。 并在这些链接之前包含https:// 。 我也遇到过这个问题。 但现在它的工作。
为了让桌子工作,你可以做的是,
$(window).load(()=>{
setTimeout(() => {
$('table').DataTable();
}, 1100);
})
添加$.noConflict();
到您的脚本:
<script type="text/javascript">
$.noConflict();
$(document).ready(function(){
$('#myTable').DataTable();
});
</script>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.