2016-07-20 73 views
0

我想實現Datatables jQuery插件與我的HTML表,但沒有運氣。我鏈接到CSS樣式和Datatables腳本本身的Datatables CDN,同時鏈接到Google託管的jquery插件。我也有一個腳本的本地Javascript文件來初始化我桌子上的數據表。我去打開html頁面,只是得到我的普通表,就好像DataTable甚至沒有運行。我可能做錯了什麼?DataTables jquery插件不工作,得到一個空白頁?

<link rel="stylesheet" type="text/css" href="http://cdn.datatables.net/1.10.12/css/jquery.dataTables.min.css"/> 
<script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/jquery/3.1.0/jquery.min.js"></script> 
<script type="text/javascript" src="http://cdn.datatables.net/1.10.12/js/jquery.dataTables.min.js"></script> 
<script type="text/javascript" src="datatables.js"></script> 

<table id="mytable"> 
<table> 
    <thead> 
    <tr> 
     <th>High-Level Category</th> 
     <th>Device Type</th> 
     <th>Hostname</th> 
     <th>IP Address</th> 
     <th>Owner</th> 
     <th>Organizational Unit</th> 
     <th>Organizational Unit Email</th> 
     <th>Universal Forwarder or Syslog?</th> 
     <th>In PCI?</th> 
     <th>Notes</th> 
    </tr> 
    </thead> 
<tbody contenteditable> 
    <tr> 
     <td contenteditable="true">SECDEV1</td> 
     <td contenteditable="true">Firewall</td> 
     <td contenteditable="true">Description 1</td> 
     <td contenteditable="true">1.1.1.1</td> 
     <td contenteditable="true">Kim</td> 
     <td contenteditable="true">Information Technology</td> 
     <td contenteditable="true">[email protected]</td> 
     <td contenteditable="true">Syslog</td> 
     <td contenteditable="true">Yes</td> 
     <td contenteditable="true">notes</td> 
    </tr> 
    <tr> 
     <td contenteditable="true">SECDEV2</td> 
     <td contenteditable="true">Switch</td> 
     <td contenteditable="true">description2</td> 
     <td contenteditable="true">2.2.2.2</td> 
     <td contenteditable="true">Bob</td> 
     <td contenteditable="true">Information Networking</td> 
     <td contenteditable="true">[email protected]</td> 
     <td contenteditable="true">Syslog</td> 
     <td contenteditable="true">NO</td> 
     <td contenteditable="true">more notes</td> 
    </tr> 
</tbody> 

本地的js文件我有如下:

$(document).ready(function(){ 

    $('#mytable').dataTable(); 

}); 

任何幫助將是巨大的。

謝謝!

+0

爲什麼都datatables.js和DataTable min.js.刪除datatables.js。 – Ranjan

+0

datatables.js是初始化DataTables的本地JavaScript腳本。那是datatables.min.js從Datatables CDN做些什麼? – Zach

+0

兩者都是相同的,但min.js是縮小版本。只需刪除它並檢查它。 – Ranjan

回答

1

您的HTML代碼不正確。有一個額外開放結尾表標記。我糾正你的下面的html:

<table id="mytable"> 
     <thead> 
     <tr> 
      <th>High-Level Category</th> 
      <th>Device Type</th> 
      <th>Hostname</th> 
      <th>IP Address</th> 
      <th>Owner</th> 
      <th>Organizational Unit</th> 
      <th>Organizational Unit Email</th> 
      <th>Universal Forwarder or Syslog?</th> 
      <th>In PCI?</th> 
      <th>Notes</th> 
     </tr> 
     </thead> 
     <tbody contenteditable> 
      <tr> 
       <td contenteditable="true">SECDEV1</td> 
       <td contenteditable="true">Firewall</td> 
       <td contenteditable="true">Description 1</td> 
       <td contenteditable="true">1.1.1.1</td> 
       <td contenteditable="true">Kim</td> 
       <td contenteditable="true">Information Technology</td> 
       <td contenteditable="true">[email protected]</td> 
       <td contenteditable="true">Syslog</td> 
       <td contenteditable="true">Yes</td> 
       <td contenteditable="true">notes</td> 
      </tr> 
      <tr> 
       <td contenteditable="true">SECDEV2</td> 
       <td contenteditable="true">Switch</td> 
       <td contenteditable="true">description2</td> 
       <td contenteditable="true">2.2.2.2</td> 
       <td contenteditable="true">Bob</td> 
       <td contenteditable="true">Information Networking</td> 
       <td contenteditable="true">[email protected]</td> 
       <td contenteditable="true">Syslog</td> 
       <td contenteditable="true">NO</td> 
       <td contenteditable="true">more notes</td> 
      </tr> 
     </tbody> 
    </table> 
1

實現你預期的效果,請使用以下CDN庫

<!-- DataTables CSS --> 
<link rel="stylesheet" type="text/css" href="http://ajax.aspnetcdn.com/ajax/jquery.dataTables/1.9.4/css/jquery.dataTables.css"> 

<!-- jQuery --> 
<script type="text/javascript" charset="utf8" src="http://ajax.aspnetcdn.com/ajax/jQuery/jquery-1.8.2.min.js"></script> 

<!-- DataTables --> 
<script type="text/javascript" charset="utf8" src="http://ajax.aspnetcdn.com/ajax/jquery.dataTables/1.9.4/jquery.dataTables.min.js"></script> 

Codepen- http://codepen.io/nagasai/pen/AXyLXO

+0

@zach,如果我的回答幫助你的問題,請將其標記爲已回答:) –