2017-06-20 94 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文件我只是有一个变量,文件撰写。非常简单并且有效地工作。