我是 JQuery 的新手。我有一张 table 。我想在我的表中应用两个插件。我使用 Tablesorter 和 tablescroll 插件。
我包含的 Javascript 文件:
<script type="text/javascript" src="js/jquery-latest.js"></script>
<script type="text/javascript" src="js/jquery.tablesorter.min.js"></script>
<script type="text/javascript" src="js/jquery.tablescroll.js"></script>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.0/jquery.min.js"></script>
当我在我的 HTML 的 head 部分包含下面给定的代码时,没有任何效果。 当我将它包含在文件末尾时,就在结束正文标签之后,表格滚动功能起作用。表格排序根本不起作用。
<script type="text/javascript">
jQuery(document).ready(function($)
{
$('#showconnections').tableScroll({height:500});
$('#showconnections').tablesorter();
});
</script>
我检查了控制台,给出了以下错误:
Uncaught TypeError: undefined is not a function
我的表格标签很简单。
<table id="myTable" cellspacing="0" class="table table-bordered table-responsive table-striped tablesorter" border="1">
<thead>
<tr>
<th rowspan="2">city id</th>
<th rowspan="2">state name</th>
<th rowspan="2">cityname</th>
<th rowspan="2">state code</th>
<th rowspan="2">zip code</th>
</tr>
</thead>
<tbody>
<tr>
<td>fdfd</td>
<td>ddffd</td>
<td>dffd</td>
<td>dfdf</td>
<td>fgfd</td>
</tr>
</tbody>
</table>
注意:上面给出了表格标签的结构。数据是虚拟的。我的表包含多行。
最佳答案
我已经为你创建了 fiddle 。请查看它。 JavaScript 代码必须是这样的
<script type="text/javascript">
$(document).ready(function()
{
$("#myTable").tablesorter();
$('#myTable').tableScroll({height:300});
}
);
</script>
注意:
- "$('#showconnections')"哪个元素有 id"showconnections",如果你的意思是你的表那么它必须是 "myTable"
- 您的插件“TableScroll”和“Table Sorted”结合在一起,不适合 UI。
关于javascript - JQuery 插件报错,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23779345/