更改表格列顺序 [英] Change table columns order
问题描述
我需要动态改变html / js中表格的列顺序,你可以告诉我该怎么做?
谢谢大家!
I need to change the order of columns in a table in html / js dynamically, you can tell me how to do? Thank you all!
推荐答案
如果您只需要简单地移动一个没有任何花哨的拖放动画的列,下面的JS应该这样做:
If you only require to simply move a column without any fancy drag-drop animation, the following JS should do the trick:
<script type="text/javascript">
$(function() {
jQuery.each($("table tr"), function() {
$(this).children(":eq(1)").after($(this).children(":eq(0)"));
});
});
</script>
根据需要替换数字。这个概念有效
看起来,把它写成一行就不太可能。包括选择器中的td,即使行选择器似乎在单独的索引中保存了每个td ,而忽略了行。
It seems that writing this as a one liner isn't really possible. including td in the selector, even with the row selector seems to hold each td on a separate index, ignoring rows.
一个jQuery网格插件应该做的伎俩,否则。虽然我没有这种插件的经验。
A jQuery grid plugin should do the trick otherwise. Although I have no experience with such plugins.
这篇关于更改表格列顺序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!