【问题标题】:Add thead and insert first tr from tbody for parent table only仅为父表添加thead并从tbody插入第一个tr
【发布时间】:2014-04-25 10:58:51
【问题描述】:

我必须使用 tbody 的第一行创建一个thead。我没有完全控制标记,所以我使用 jQuery 来执行此操作。

我已经成功使用了一些借来的脚本,但是当我向一个页面添加多个表时,第一行似乎在以下表中重复

我想我需要定位父表,通常我会给每个表一个 ID,但我不能,因为这些是为我生成的。

在这个小提琴http://jsfiddle.net/FGH6B/中可以看到正在发生的事情的一个例子

我现在的jquery如下

jQuery("document").ready( function() {

    var mytable = $("table"); 

    mytable.prepend(document.createElement('thead'));

    $("table thead").append($("tbody tr:eq(0)"));

});

【问题讨论】:

  • 但是在你的小提琴中,没有父表。
  • 抱歉术语使用不当。我的意思是当前表。
  • 那么您是否期望与 Milind 的答案相同的输出?

标签: jquery html html-table semantic-markup


【解决方案1】:

试试这个:

$("document").ready( function() {
    $('table').each(function(){
    $(this).prepend('<thead></thead>')
    $(this).find('thead').append($(this).find("tr:eq(0)"));
})});

Working Demo

【讨论】:

    猜你喜欢
    • 2012-09-28
    • 1970-01-01
    • 2018-12-09
    • 1970-01-01
    • 2015-03-08
    • 2012-01-05
    • 2017-01-24
    • 2012-08-30
    • 1970-01-01
    相关资源
    最近更新 更多