我是编码新手,我不知道我的问题可能很简单,但我最近开始学习编码。
对于我的简单应用程序,我想对表格进行排序并为其提供一个搜索框。
我尝试下载最新的 jquery.tablesorter.js、widgets-filter.js。并尝试对基本表格进行排序。但我无法让它发挥作用。我无法正确找到任何示例下载文件,以便我尝试理解它。在我见过的大多数插件中,都有一个可以下载的演示文件夹,其中包含插件的基本演示。
对于我的应用程序,我需要根据页面加载和加载后的两列对表格进行排序,我必须能够使用搜索框进行搜索。如此处提供的演示 https://mottie.github.io/tablesorter/docs/example-widget-filter-any-match.html
我尝试查看该页面的源代码并尝试使用那里使用的相同插件,但我无法使其工作。 有人可以帮助我让它工作并指出我可以在哪里下载演示文件夹或类似的东西,以便我可以理解它。
最佳答案
这是一个使用过滤器小部件和外部搜索输入的简化演示:https://jsbin.com/qahuba/1/edit?html,output
基本 HTML
<input type="text" data-column="all" class="search">
<table><!-- thead & tbody required --></table>
基本脚本
<script src="//code.jquery.com/jquery-git.js"></script>
<script src="https://mottie.github.io/tablesorter/js/jquery.tablesorter.js"></script>
<script src="https://mottie.github.io/tablesorter/js/jquery.tablesorter.widgets.js"></script>
<script>
/* Documentation for this tablesorter FORK can be found at
* http://mottie.github.io/tablesorter/docs/
*/
$(function() {
$('table').tablesorter({
theme: 'blue',
widgets: ['zebra', 'filter'],
widgetOptions: {
// jQuery selector string (or jQuery object) of external filters
filter_external: '.search',
// If true, a filter will be added to the top of each table column.
filter_columnFilters: false
}
});
});
</script>
注意:在生产中,指向您自己的服务器上或来自稳定 CDN 源的 jQuery 和 tablesorter 文件(即不是 jquery-git.js
文件或直接来自 github 的文件)。
关于javascript - tablesorter 插件,我无法使其工作,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40362170/