自动按表格最后一列中的最大值对表格进行排序 [英] Automatically order table by highest value in last column of table

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

问题描述

我一直无法找到一种方法来做到这一点.我需要表格从高到低(降序)自动排列.我无法直接访问该表的HTML,它是自动生成的.请帮忙.

I have been unable to find a way to do this. I need the table to automatically be arranged by the amount raised from high to low (descending order). I cannot access the HTML for the table directly, it is automatically generated. Please help.

<table>
    <tr>
        <td>team name </td>
        <td>team capain</td>
        <td>amount raised</td>
    </tr>
    <tr>
        <td>team 1</td>
        <td>captain1</td>
        <td>CAN$0.00</td>
    </tr>
    <tr>
        <td>team 2</td>
        <td>captain2</td>
        <td>CAN$5.00</td>
    </tr>
    <tr>
        <td>team 3</td>
        <td>captain3</td>
        <td>CAN$3.00</td>
        </tr>
    <tr>
        <td>team 4</td>
        <td>captain4</td>
        <td>CAN$20.00</td>
    </tr>
</table>

推荐答案

您使用了标记jquery,因此我将假定即使您无法编辑html,您仍然可以使用js不知何故.

You used the tag jquery so I'm going to assume that even though you can't edit the html, you can still modify the page with js somehow.

因此,如果您想使用jquery插件,这是一个不错的插件: http://tablesorter.com/

So if you want to use a jquery plugin, here is a good one: http://tablesorter.com/

但是,如果您只想使用普通香草js,我见过的另一个不错的选择是: http://www.kryogenix.org/code/browser/sorttable/

However, if you want to use just plain vanilla js another good one I've seen is this: http://www.kryogenix.org/code/browser/sorttable/

这是第二个选项的工作示例(我建议这样做,因为它不需要像jquery这样的<thead>标签:

Here is a working example of the second option (which I recommend since it doesn't need <thead> tags like the jquery one: http://jsfiddle.net/g6XM7/

这篇关于自动按表格最后一列中的最大值对表格进行排序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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