我正在尝试使用此脚本对 html 表进行排序:http ://www.kryogenix.org/code/browser/sorttable/
JS 代码本身:http ://www.kryogenix.org/code/browser/sorttable/sorttable.js
我使用了该customkey选项,当我单击标题时它可以工作。我想customkey在页面加载时根据它自动排序。我怎样才能做到这一点?我想使用这个特定的脚本。我试过window.onload但没有运气。
我正在尝试使用此脚本对 html 表进行排序:http ://www.kryogenix.org/code/browser/sorttable/
JS 代码本身:http ://www.kryogenix.org/code/browser/sorttable/sorttable.js
我使用了该customkey选项,当我单击标题时它可以工作。我想customkey在页面加载时根据它自动排序。我怎样才能做到这一点?我想使用这个特定的脚本。我试过window.onload但没有运气。
加载页面后,只需单击要排序的标题列。尝试使用以下javascript代码。我假设页面中只有一个表。也许您需要更具体地使用getElementsByTagName或getElementById代替。[1]是列号。在此之前您不需要附加点击处理程序,因为该任务是由sorttable.js.
<script src="js/sorttable.js"></script>
<script>
window.onload = function() {
(document.getElementsByTagName( 'th' )[1]).click();
};
</script>
我解决了这个问题略有不同。在我想要点击页面加载的任何表头上,我添加了data-autoclick="true". 然后在我的主应用程序 JavaScript 中,我添加了
<script>
window.onload = function() {
$('[data-autoclick="true"]').click();
};
</script>
如何使用
table.sortable th:not(.sorttable_sorted):not(.sorttable_sorted_reverse):not(.sorttable_nosort):after {
content: " \25B4\25BE"
}
在动态表中。