更改表列顺序 [英] 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 it?
推荐答案
如果你只需要简单地移动一列而不需要任何花哨的拖放动画,下面的 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屋!
查看全文