【问题标题】:Jquery Tablesorter not working! What's wrong with that?Jquery Tablesorter 不工作!那有什么问题?
【发布时间】:2016-10-05 10:39:34
【问题描述】:

我是 Jquery 的新手,我正在尝试使用 Jquery Tablesorter 插件,我已经在一个简单的 html 文件中对其进行了测试,如下所示,但它不起作用。我在浏览器中看到的只是一个没有排序的普通表格,没有可点击的标题,它看起来不像我在 Jquery Tablesorter 主页上看到的那样。我不知道我的html有什么问题。我已将 2 个 jquery 文件与此 html 文件放在同一文件夹中。请指教!

<html>
<head>
<script type="text/javascript" src="jquery-1.9.1.min.js"></script>
<script type="text/javascript" src="jquery.tablesorter.js"></script> 
<script type="text/javascript">
$(document).ready(function() 
    { 
         $("#myTable").tablesorter( {sortList: [[0,0], [1,0]]} ); 
    } 
); 
</script>
</head>
<body>  
<table id="myTable" class="tablesorter"> 
<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> 
</body>
</html>

【问题讨论】:

  • 没有 css 文件要包含吗?
  • 我还会检查您的浏览器控制台并确保这些文件正在加载(只是为了确定)
  • @leppie 是的,我已经包含默认主题 css
  • 你能创建一个你的代码的 jsfiddle 链接以便我们使用它吗?
  • @Dead Man 是的,请先生。这里是jsfiddle.net/twentyle/BKgue

标签: jquery tablesorter


【解决方案1】:

这是工作小提琴链接。您忘记添加我在 jsfiddle 的外部资源中添加的 tablesorter jstablesorter css。你可以检查一下。

http://jsfiddle.net/BKgue/2/

【讨论】:

  • 好的,我已经理解,修复了,现在可以了 :)。谢谢先生,谢谢!
  • 说明您需要 tablesorter js 和 tablesorter css 文件的文档在哪里?
  • 是的,我阅读了整个文档,完全没有关于必须添加 tablesorter.css 才能使其工作的参考。对我来说毫无意义。
  • @Laurent 在我在这里阅读了每个人的 cmets 之后,我也为此苦苦挣扎了很长时间。然后我意识到我仍然在 中使用 而不是 。也许你有同样的问题?
  • 我遇到了同样的问题,结果我错过了在我的表格中使用 thead 和 tbody html 标签。显然 tablesorter 依赖于它们。
【解决方案2】:

注意 &lt;th&gt;&lt;tr&gt; 内而不是 &lt;td&gt; 这是阻止它为我工作的原因。

 <thead>
    <tr>
       <th>column 1</th>
    <tr>
</thead>

tablesorter 也不需要 css 来工作。如果您想保留自己的格式,但又希望显示小箭头,则只需要以下代码。并将tablesorter提供的3箭头gif复制粘贴到与css文件相同的文件夹中。或者你自己的箭头 gif,如果你愿意的话。

table.tablesorter thead tr .header {
    background-image: url(bg.gif);
    background-repeat: no-repeat;
    background-position: center right;
    cursor: pointer; 
}
table.tablesorter thead tr .headerSortUp {
    background-image: url(asc.gif);
}
table.tablesorter thead tr .headerSortDown {
    background-image: url(desc.gif);
}

【讨论】:

    猜你喜欢
    相关资源
    最近更新 更多
    热门标签