Ric*_*ard 11 javascript jquery html-table
有没有人知道使用jQuery重新排序表列的方法?
我不是指排序 - 我的意思是在表格中左右移动整个列.
我知道优秀的可拖动插件,但我不需要允许用户移动列的东西,我需要能够以可配置的方式进行重新排序的东西.
sca*_*zet 11
想法是遍历表的所有行(tr)并交换所需的td.让我们交换第2列和第4列:
$('table tr').each(function() {
var tr = $(this);
var td1 = tr.find('td:eq(1)'); // indices are zero-based here
var td2 = tr.find('td:eq(3)');
td1.detach().insertAfter(td2);
});
Run Code Online (Sandbox Code Playgroud)
我希望这有帮助.
这段代码应该适合你。
$("table tr").each(function () {
$(this).find("td").eq(1).after($(this).find("td").eq(0));
});
Run Code Online (Sandbox Code Playgroud)
$("table tr").each(function () {
var rows = $(this).find("td");
rows.eq(1).after(rows.eq(0));
});
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
14752 次 |
| 最近记录: |