使用sorttable.js自动对表进行排序

use*_*034 5 html javascript sorting sorttable.js

我正在尝试使用此脚本对html表进行排序:http://www.kryogenix.org/code/browser/sorttable/

JS代码本身:http://www.kryogenix.org/code/browser/sorttable/sorttable.js

我使用了该customkey选项,当我点击标题时它可以工作.我想基于customkey页面加载时自动排序.我怎样才能做到这一点?我想使用这个特定的脚本.我试过window.onload但没有运气.

Bir*_*rei 6

加载页面后,只需触发要排序的标题列的单击.尝试使用以下javascript代码.我假设页面中只有一个表.也许您需要更具体地使用getElementsByTagNamegetElementById改为使用.这[1]是列号.您之前不需要附加单击处理程序,因为该任务是由代码完成的sorttable.js.

<script src="js/sorttable.js"></script>
<script>
    window.onload = function() {
        (document.getElementsByTagName( 'th' )[1]).click();
    };
</script>
Run Code Online (Sandbox Code Playgroud)