使用sorttable.js自动对表进行排序 [英] Auto sort the table using sorttable.js

查看:401
本文介绍了使用sorttable.js自动对表进行排序的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

I am trying to use this script to sort the html table: http://www.kryogenix.org/code/browser/sorttable/

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

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

I used the customkey option and it works when I click the heading. I would like to auto sort based on that customkey when the page loads. How can I do that? I want to use this specific script. I tried window.onload but with no luck.

推荐答案

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

After loading the page just trigger a click on the header column you want to sort. Try with following javascript code. I assume that there is only one table in the page. Perhaps you will need to be more specific using getElementsByTagName or with getElementById instead. The [1] is the column number. You don't need to attach a click handler before that because that task is done by the code of sorttable.js.

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

这篇关于使用sorttable.js自动对表进行排序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆