【发布时间】:2016-11-16 02:13:12
【问题描述】:
与这个问题非常相似:Sort table rows based on their Class Names
考虑下表:
<table>
<thead>
<th>A column</th>
</thead>
<tbody>
<tr>
<td class="x">A</td>
</tr>
<tr>
<td class="c">B</td>
</tr>
<tr>
<td class="">C</td>
</tr>
</tbody>
</table>
我想根据第一个(仅在这种情况下)列类名称对行进行排序。一些td 没有指定类。所以想要的效果是:A-B-C -> C-B-A or B-A-C(我不在乎无类 tds 放在哪里)。我知道我可以用 jquery 上课,例如:
$(table tr).eq(1).find('td').eq(0).attr('class')
有什么想法吗?
【问题讨论】:
-
请提供尝试过的解决方案,为什么它们不起作用,以及预期的结果。这确实有助于我们找出您的代码的问题。谢谢!
标签: javascript jquery html sorting html-table