【问题标题】:Take a TD, and insert it after the second TD in the parent TR取一个 TD,并将其插入到父 TR 中的第二个 TD 之后
【发布时间】:2012-08-30 04:17:16
【问题描述】:

我有一张桌子。我想在每个 TR 中获取所有第九个 TD,并将其放在同一个 TR 中的第一个原始 TD 之后。

此代码采用第九个 TD,并将其放在父 TR 之后。我想把它放在同一个 TR 中的第一个原始 TD 之后:

$('td:nth-child(9)').each( function(){
   $(this).prependTo($(this).parent());
});

我需要的是等价于:

.parent():first-child

【问题讨论】:

  • 你想让第九个td变成第二个td还是放在之后原来的第二个td
  • 我搞砸了,对不起。我希望它位于第一个原始 TD 之后。我编辑了我的问题。

标签: jquery html-table jquery-selectors


【解决方案1】:
$('td:nth-child(9)').each( function(){
    $(this).siblings('td:first').after(this);
});

FIDDLE

【讨论】:

  • siblings('td:eq(0)') 更短。
  • @VisioN - 很好,将 eq 移到选择器中!这个问题似乎每五分钟就会改变一次!
【解决方案2】:

试试这个

$('td:nth-child(9)').each( function(){

            $(this).siblings('td').eq(0).after(this);
 });

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-12-08
    • 1970-01-01
    • 2013-08-23
    • 1970-01-01
    • 2013-10-12
    • 2012-11-23
    相关资源
    最近更新 更多