2017-04-05 136 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 =”作为文件

相关问题