【问题标题】:Auto sort the table using sorttable.js使用 sorttable.js 对表格进行自动排序
【发布时间】:2012-12-14 21:28:50
【问题描述】:
【问题讨论】:
标签:
javascript
html
sorting
sorttable.js
【解决方案1】:
加载页面后,只需点击您要排序的标题列即可。尝试以下javascript 代码。我假设页面中只有一个表。也许您需要更具体地使用getElementsByTagName 或getElementById。 [1] 是列号。在此之前您不需要附加点击处理程序,因为该任务由 sorttable.js 的代码完成。
<script src="js/sorttable.js"></script>
<script>
window.onload = function() {
(document.getElementsByTagName( 'th' )[1]).click();
};
</script>
【解决方案2】:
我解决了这个问题略有不同。在我想要点击页面加载的任何表头上,我添加了data-autoclick="true"。然后在我的主应用程序 JavaScript 中,我添加了
<script>
window.onload = function() {
$('[data-autoclick="true"]').click();
};
</script>
【解决方案3】:
如何使用
table.sortable th:not(.sorttable_sorted):not(.sorttable_sorted_reverse):not(.sorttable_nosort):after {
content: " \25B4\25BE"
}
在动态表中。