2017-06-20 49 views
0

好的,所以我有一個HTML jquery tablesorter網頁。我不想將所有「td」標籤嵌入到同一個文件中,而是希望從單獨的文件中加載它們。原因是數據非常大,而且它是模塊化所必需的。下面是我想到目前爲止....包含外部html表格數據

 <div id="demo"><table class="tablesorter"> 
<script src="https://www.w3schools.com/lib/w3.js"> w3.includeHTML();</script> 
     <br> 
       <!-- Table Head --> 
       <thead> 
        <tr> 
         <th>Sensor</th> <!-- disable dragtable on this column --> 
         <th class="drag-enable">c1</th> 
         <th class="drag-enable">c2</th> 
         <th class="drag-enable">c3</th> 
         <th class="drag-enable">c4</th> 
         <th class="drag-enable">c5</th> 
         <th class="drag-enable">c6</th> 
        </tr> 
       </thead> 
       <!-- Table Footer --> 
       <tfoot> 
        <tr><th>c1</th><th>c2</th><th>c3</th><th>c4</th><th>c5</th><th>c6</th><th>c7</th></tr> 
       </tfoot> 
       <!-- Table Content --> 
       <tbody w3-include-html="C:\Users\user\Desktop\new_test\tabledata.html"> 
       </tbody> 
      </table> 
     </div> 
+0

那麼,你面臨什麼問題? –

+0

如果你有很多數據,那麼你不應該使用JavaScript加載它。瀏覽器將無法響應,直到數據加載。我會建議你只在瀏覽器中加載必要的數據(像一次20行)... –

+0

我可以直接粘貼它,因此使用文件。它更多關於模塊性,因爲表數據文件被另一個程序修改。這不是一個巨大的數據量,即沒有顯着的不響應從瀏覽器 – Seb

回答

0

按我的理解,你有沒有初始化w3.includeHTML()方法正確。

的問題是,你需要在你的HTML代碼

試試下面的代碼結束初始化w3.includeHTML();

<!DOCTYPE html> 
<html> 
<script src="https://www.w3schools.com/lib/w3.js"></script> 
    <body> 
    <div id="demo"> 
    <table class="tablesorter">   
      <br> 
        <!-- Table Head --> 
        <thead> 
         <tr> 
          <th>Sensor</th> <!-- disable dragtable on this column --> 
          <th class="drag-enable">c1</th> 
          <th class="drag-enable">c2</th> 
          <th class="drag-enable">c3</th> 
          <th class="drag-enable">c4</th> 
          <th class="drag-enable">c5</th> 
          <th class="drag-enable">c6</th> 
         </tr> 
        </thead> 
        <!-- Table Footer --> 
        <tfoot> 
         <tr><th>c1</th><th>c2</th><th>c3</th><th>c4</th><th>c5</th><th>c6</th><th>c7</th></tr> 
        </tfoot> 
        <!-- Table Content --> 
        <tbody w3-include-html="C:\Users\user\Desktop\new_test\tabledata.html"> 
        </tbody> 
       </table> 
      </div> 
     <script> 
     w3.includeHTML(); 
     </script> 
</body> 
</html> 

試試這個,讓我知道,如果你面對的課題。

+0

嗯,仍然沒有運氣 – Seb

+0

你面臨什麼問題? –

0

我得到它的工作是這樣的:

  <table id="table" class="tablesorter"> 

       <script src="columndata.js"></script> 

      </table> 

然後在js文件我只是有一個變量,文件撰寫。非常簡單並且有效地工作。