如何用jQuery拆分表行(在TD之间插入TR)
我有一些问题用jQuery分割表。
这是表:
A B C D E F G H
我想在调用函数后让它看起来像这样:
A B C D E F G H
我尝试过:
$(function(){ $('.submenu td:eq(3)').after(''); });
请尝试使用此代码段:
$(function(){ // # Add a new row after the first one in the table $('table#submenu tr:first').after(' '); // # Move the four last TDs to this new row $('table#submenu tr:first td.submenu:gt(3)') // Select the four last TDs .detach() // Detach them from their current row .appendTo('table#submenu tr:nth-child(2)'); // Add them at the end of the new row });
A B C D E F G H
这会奏效。
这段代码解决了你的问题。
$(document).ready(function(){ $("table tr td:nth-child(5n)").addClass('break'); var boundary = $("td.break"); $("").insertAfter(boundary.parent()).append(boundary.nextAll().andSelf()); });
DEMO