gpt4 book ai didi

javascript - JQuery TableSort 不适用于 JQuery floatThead

转载 作者:行者123 更新时间:2023-11-29 20:48:59 25 4
gpt4 key购买 nike

我有下面的 MCVE 和来自 tablesorter@github 的示例表

单击表格标题可对表格进行排序。当我添加此行时 $('table#myTable').floatThead(); 在此示例中进行了注释,然后它停止工作。

知道问题是什么以及如何解决吗?

<html lang="en">
<head>
<title>JQuery table sorter with JQuery floatThead MCVE</title>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<script src="https://code.jquery.com/jquery-3.3.1.min.js"></script>
<script src="https://rawgit.com/christianbach/tablesorter/master/jquery.tablesorter.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/floatthead/2.1.2/jquery.floatThead.min.js"></script>
</head>
<body>
<table id="myTable" class="tablesorter" border=1>
<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>$40.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>$51.00</td>
<td>http://www.timconway.com</td></tr>
</tbody>
</table>

<script type="text/javascript">
//$('table#myTable').floatThead();
$(document).ready(function() { $("#myTable").tablesorter(); }
);
</script>
</body>
</html>

最佳答案

我偶然发现了一个非常简单的解决方案:顺序很重要!只需添加 $('table#myTable').floatThead(); AFTER 函数 tablesorter() 已被调用。

<html lang="en">
<head>
<title>JQuery table sorter with JQuery floatThead MCVE</title>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<script src="https://code.jquery.com/jquery-3.3.1.min.js"></script>
<script src="https://rawgit.com/christianbach/tablesorter/master/jquery.tablesorter.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/floatthead/2.1.2/jquery.floatThead.min.js"></script>
</head>
<body>
<table id="myTable" class="tablesorter" border=1>
<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>$40.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>$51.00</td>
<td>http://www.timconway.com</td></tr>
</tbody>
</table>

<script type="text/javascript">
$(document).ready(function() { $("#myTable").tablesorter(); $('table#myTable').floatThead(); }
);
</script>
</body>
</html>

关于javascript - JQuery TableSort 不适用于 JQuery floatThead,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52891595/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com