[英]jQuery - change table cells position
how can I change via jquery the cells position from 1 2
to 2 1
? 如何通过jquery将单元格位置从
1 2
更改为2 1
?
<table id='mytable'>
<tr>
<td>1</td>
<td>2</td>
</tr>
</table>
$('#mytable tr td:eq(0)').appendTo('#mytable tr');
JSFIDDLE 。
If you want to change all the second td
to first position in your table, then you can use: 如果要将所有第二个
td
更改为表中的第一个位置,则可以使用:
$.each($('#mytable tr td:eq(1)'), function() {
$(this).insertBefore($(this).prev());
})
<tr>
element, if that is the case then you need to use .find()
:
<tr>
元素,则上述代码将不起作用,如果是这种情况,则需要使用.find()
:
$('#mytable tr').find('td:eq(1)').each(function() {
$(this).insertBefore($(this).prev());
});
References: .each() , .find() , .insertBefore() , .prev() 参考文献: 。每个() , .find() , .insertBefore() , .prev()
with append 带附加
http://jsfiddle.net/F7HmQ/1/ http://jsfiddle.net/F7HmQ/1/
$(function(){
var td = $("td").first() ;
$("tr").first().append(td);
});
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.