2017-04-05 84 views
-2

我正在嘗試此操作http://jsfiddle.net/fy63opLq/此腳本適用於此URL,但是當我在本地執行此操作時,它給了我此錯誤消息:未捕獲的ReferenceError:$不是在xxxx.php定義:4 屬於此行$(文件)。就緒(函數(){ 誰能幫助確定哪些原因此錯誤消息

<html> 
<head> 
<script> 
     $(document).ready(function() { 
     var t = $('#thetable tbody').eq(0); 
     var r = t.find('tr'); 
     var cols= r.length; 
     var rows= r.eq(0).find('td').length; 
     var cell, next, tem, i = 0; 
     var tb= $('<tbody></tbody>'); 
     while(i<rows){ 
      cell= 0; 
      tem= $('<tr></tr>'); 
      while(cell<cols){ 
       next= r.eq(cell++).find('td').eq(0); 
       tem.append(next); 
      } 
      tb.append(tem); 
      ++i; 
     } 
     $('#thetable').append(tb); 
     $('#thetable').show(); 
    }); 

    </script> 
</head> 
<body> 
<table id="thetable" class="table table-striped"> 

<tr> 
    <td>Table header</td> 
    <td>Table header</td> 
    <td>Table header</td> 
    </tr> 
<tbody> 
    <tr> 
    <td>cell1</td> 
    <td>cell1</td> 
    <td>cell1</td> 
    </tr> 
    <tr> 
    <td>cell2</td> 
    <td>cell2</td> 
    <td>cell2</td> 
    </tr> 
    <tr> 
    <td>cell3</td> 
    <td>cell3</td> 
    <td>cell3</td> 
    </tr> 
</tbody> 
</table> 
</body> 
</html> 
+1

你需要包括jQuery腳本第一 – gurvinder372

+0

在撥弄你可能有附加的jQuery的位置,但在當地你可能不是。 –

+0

添加jQuery庫 –

回答

0

您還沒有jquery庫在您的html文件中。

第一script標籤

<script src="https://code.jquery.com/jquery-3.2.0.min.js"></script> 

之前添加此行從Google CDN

<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.2.1/jquery.min.js"></script> 
+0

謝謝大家,它現在可用!非常感謝! – nat8991

0

你忘了jQuery的添加到您的腳本。添加

<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>

到HTML的頂部,它應該工作

0

添加以下代碼在你head標籤。

<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.1.0/jquery.min.js"></script> 

更改jQuery的版本3.1.0相應

0

該腳本適用於的jsfiddle,因爲它擁有jQuery的鏈接。

使用此標籤包含jquery而無需下載它。最新的jQuery:

<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.2.1/jquery.min.js"></script> 

或下載jQuery的本地https://jquery.com/download/並使用腳本「SRC =」作爲文件

相關問題