javascript - JQuery 插件报错

标签 javascript php jquery html tablesorter

我是 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>

注意:上面给出了表格标签的结构。数据是虚拟的。我的表包含多行。

最佳答案

http://jsfiddle.net/LFBmL/2/

我已经为你创建了 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/

相关文章:

javascript - 我们可以在 Angular 中使用 Jasmine/Karma 测试 ngrx 流吗?

javascript - 如何使用正则表达式替换标签之间的文本

javascript - 抓取动态表单 WWW::Mechanize Perl

php - 是否可以在 CakePHP 的同一 View 中对两个不同的模型进行分页和排序?

Android debuggable=false 导致 jQuery.ajax POST 在 Cordova/Phonegap Eclipse 项目中失败

javascript - 一个文件中有多个函数?

javascript - 生命游戏 p5.js 无法更新单元格

php - Laravel - HTML POST 表单,找不到页面

php - mysql 查询两个表,为每个 session 检索消息

jquery - 使用 jQuery.animate 在 Adob​​e AIR 中制作动画