javascript - 尝试在我的 table 上使用 jquery.tablesorter 插件,但它不起作用

标签 javascript jquery html cdn tablesorter

我正在尝试在一个简单的表格上使用 jquery.tablesorter 来做一些练习,我已经将 tablesorter js 和 css 的 CDN 链接添加到我的 HTML <head> 。另外,我使用每个基于 CDN 的库(包括 jQuery、bootstrap 等)来明确问题。我在下面附上了我的代码,任何人都可以帮助找到我的代码中的任何错误以阻止 tablesorter 运行。

<!DOCTYPE html>
<html>

<head>
    <title></title>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
    <!-- JQuery -->
    <script src="https://code.jquery.com/jquery-3.2.1.js" integrity="sha256-DZAnKJ/6XZ9si04Hgrsxu/8s717jcIzLy3oi35EouyE=" crossorigin="anonymous"></script>
    <!-- Latest compiled and minified CSS -->
    <link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css" rel="stylesheet" integrity="sha384-BVYiiSIFeK1dGmJRAkycuHAHRg32OmUcww7on3RYdg4Va+PmSTsz/K68vbdEjh4u"
        crossorigin="anonymous">
    <!-- Latest compiled and minified JavaScript -->
    <script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js" integrity="sha384-Tc5IQib027qvyjSMfHjOMaLkfuWVxZxUPnCJA7l2mCWNIpG9mGCD8wGNIcPD7Txa"
        crossorigin="anonymous"></script>

    <script src="https://cdnjs.cloudflare.com/ajax/libs/jquery.tablesorter/2.29.0/js/jquery.tablesorter.combined.js" integrity="sha256-AQTn9CwiNvZG2zsoT0gswugjZp0alCQySLyt9brT9Cg="
        crossorigin="anonymous"></script>
    <script src="https://cdnjs.cloudflare.com/ajax/libs/jquery.tablesorter/2.29.0/js/jquery.tablesorter.js" integrity="sha256-serXvhbeEKdQIfTFSD3wpNCGNx2+/9py7VXfwLhYTfk="
        crossorigin="anonymous"></script>
    <script src="https://cdnjs.cloudflare.com/ajax/libs/jquery.tablesorter/2.29.0/js/jquery.tablesorter.widgets.js" integrity="sha256-U+0DXO4scYcNVpt7pnud6Fx3KZqK2I5mI6KOeAjSqOE="
        crossorigin="anonymous"></script>
    <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/jquery.tablesorter/2.29.0/css/theme.bootstrap_3.min.css"
        integrity="sha256-dXZ9g5NdsPlD0182JqLz9UFael+Ug5AYo63RfujWPu8=" crossorigin="anonymous" />
    <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/jquery.tablesorter/2.29.0/css/theme.default.min.css"
        integrity="sha256-kZJ4kB78IbXuxMtCpmaXzii8vxEKtu8pjicH62E0/qM=" crossorigin="anonymous" />
    <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/jquery.tablesorter/2.29.0/css/theme.bootstrap.min.css"
        integrity="sha256-dXZ9g5NdsPlD0182JqLz9UFael+Ug5AYo63RfujWPu8=" crossorigin="anonymous" />
    <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/jquery.tablesorter/2.29.0/css/jquery.tablesorter.pager.min.css"
        integrity="sha256-x+whz5gQKEXx3S3pxwmxPhC1OWpRiHaPXUW5Yt8/fzg=" crossorigin="anonymous" />
    <style>
    </style>
    <script>

        $(document).ready(function () {
            ("#myTable").tablesorter();
        });
    </script>

</head>


<body>
    <div class="container">
        <div class="col-md-12">
            <table class="table table-striped tablesorter" id="myTable">
                <thead>
                    <tr>
                        <th>Last Name</th>
                        <th>First Name</th>
                        <th>Email</th>
                        <th>Due</th>
                        <th>Web Site</th>
                    </tr>
                </thead>
                <tbody>
                    <tr>
                        <td>Smith</td>
                        <td>John</td>
                        <td>jsmith@gmail.com</td>
                        <td>$50.00</td>
                        <td>http://www.jsmith.com</td>
                    </tr>
                    <tr>
                        <td>Bach</td>
                        <td>Frank</td>
                        <td>fbach@yahoo.com</td>
                        <td>$50.00</td>
                        <td>http://www.frank.com</td>
                    </tr>
                    <tr>
                        <td>Doe</td>
                        <td>Jason</td>
                        <td>jdoe@hotmail.com</td>
                        <td>$100.00</td>
                        <td>http://www.jdoe.com</td>
                    </tr>
                    <tr>
                        <td>Conway</td>
                        <td>Tim</td>
                        <td>tconway@earthlink.net</td>
                        <td>$50.00</td>
                        <td>http://www.timconway.com</td>
                    </tr>
                </tbody>
            </table>

        </div>

    </div>


</body>

</html>

最佳答案

正如其他人在评论中所说,您需要将 $ 放在 ("#myTable").tablesorter() 的头部才能调用它作为查询选择器。

 $(document).ready(function () {
     $("#myTable").tablesorter();
 });

关于javascript - 尝试在我的 table 上使用 jquery.tablesorter 插件,但它不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47467824/

相关文章:

javascript - 将 localStorage 中的内容附加到 div 脚本后不再起作用

Javascript:未触发 mousemove 事件处理程序

javascript - 在 knockout 中将属性绑定(bind)到模型 View 函数

javascript - 如何在循环 jQuery 中将数据存储在数组中

javascript - Cycle2 寻呼机不显示

jQuery.load 加载 HTML 文件

javascript - 存储后获取 LawnChair JSON Obj

jquery - 查询/CSS : no success in to reveal a footer hidden behind a front-page

jquery - Ruby 瘦服务器 ActionView::模板错误

html - 自定义字体(字体)在发布时不起作用