如何使用Jquery基于其值对多个表进行排序?

时间:2016-06-07 21:44:46

标签: javascript jquery

假设我们在一个页面中有多个表格,每个表格都是这样的:

<table>
<tr>
    <td class= "fi">102,215,231.02</td>
    <td class= "se">215,321</td>
    <td class= "th">1,002</td>
    <td class= "fo">0</td>
</tr>
<tr>
    <td class= "fiv">2,251</td>
    <td class= "si">55,544,444</td>
    <td class= "sev">123,000.25</td>
    <td class= "ei">25</td>
</tr>

</table>

我需要弄清楚如何使用Jquery基于它们的值(例如具有类“ei”的值)对表(不是它们的行,表本身的顺序)进行排序。我所能找到的只是如何对表的行进行排序而不是对表本身进行排序。

示例:

基于类“ei”的值,我想重新排列:

<table id="2135">
<tr>
    <td class= "fi">102,215,231.02</td>
    <td class= "se">215,321</td>
    <td class= "th">1,002</td>
    <td class= "fo">0</td>
</tr>
<tr>
    <td class= "fiv">2,251</td>
    <td class= "si">55,544,444</td>
    <td class= "sev">123,000.25</td>
    <td class= "ei">13</td>
</tr>

</table>
<table id="2131">
<tr>
    <td class= "fi">102,215,231.02</td>
    <td class= "se">215,321</td>
    <td class= "th">1,002</td>
    <td class= "fo">0</td>
</tr>
<tr>
    <td class= "fiv">2,251</td>
    <td class= "si">55,544,444</td>
    <td class= "sev">123,000.25</td>
    <td class= "ei">50</td>
</tr>

</table>
<table id="2129">
<tr>
    <td class= "fi">102,215,231.02</td>
    <td class= "se">215,321</td>
    <td class= "th">1,002</td>
    <td class= "fo">0</td>
</tr>
<tr>
    <td class= "fiv">2,251</td>
    <td class= "si">55,544,444</td>
    <td class= "sev">123,000.25</td>
    <td class= "ei">25</td>
</tr>

</table>

进入这个:

<table id="2135">
<tr>
    <td class= "fi">102,215,231.02</td>
    <td class= "se">215,321</td>
    <td class= "th">1,002</td>
    <td class= "fo">0</td>
</tr>
<tr>
    <td class= "fiv">2,251</td>
    <td class= "si">55,544,444</td>
    <td class= "sev">123,000.25</td>
    <td class= "ei">13</td>
</tr>

</table>
<table id="2129">
<tr>
    <td class= "fi">102,215,231.02</td>
    <td class= "se">215,321</td>
    <td class= "th">1,002</td>
    <td class= "fo">0</td>
</tr>
<tr>
    <td class= "fiv">2,251</td>
    <td class= "si">55,544,444</td>
    <td class= "sev">123,000.25</td>
    <td class= "ei">25</td>
</tr>

</table>
<table id="2131">
<tr>
    <td class= "fi">102,215,231.02</td>
    <td class= "se">215,321</td>
    <td class= "th">1,002</td>
    <td class= "fo">0</td>
</tr>
<tr>
    <td class= "fiv">2,251</td>
    <td class= "si">55,544,444</td>
    <td class= "sev">123,000.25</td>
    <td class= "ei">50</td>
</tr>

</table>

1 个答案:

答案 0 :(得分:0)

您可以对sudo dnf install glibc-devel.x86_64 个元素进行排序,但要替换最近的.ei个父母:

<table>

这是有效的fiddle