[英]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.