我有一个来自tablesorter@github的示例表的波纹管MCVE
单击表头对表进行排序。当我添加此示例中注释的$('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>[email protected]</td><td>$40.00</td>
<td>http://www.jsmith.com</td></tr>
<tr><td>Bach</td><td>Frank</td><td>[email protected]</td><td>$50.00</td>
<td>http://www.frank.com</td></tr>
<tr><td>Doe</td><td>Jason</td><td>[email protected]</td><td>$100.00</td>
<td>http://www.jdoe.com</td></tr>
<tr><td>Conway</td><td>Tim</td><td>[email protected]</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();
函数之后添加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>[email protected]</td><td>$40.00</td>
<td>http://www.jsmith.com</td></tr>
<tr><td>Bach</td><td>Frank</td><td>[email protected]</td><td>$50.00</td>
<td>http://www.frank.com</td></tr>
<tr><td>Doe</td><td>Jason</td><td>[email protected]</td><td>$100.00</td>
<td>http://www.jdoe.com</td></tr>
<tr><td>Conway</td><td>Tim</td><td>[email protected]</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>