jQuery add and add

前端 未结 3 775
既然无缘
既然无缘 2021-01-05 10:03

How do I add and this using jQuery?

the problem is my table has 1 or 2 th rows?

$(\'#myTable tr         


        
3条回答
  •  一整个雨季
    2021-01-05 10:33

    What you need to do is remove the rows and append them to a thead element

    var myTable = jQuery("#myTable");
    var thead = myTable.find("thead");
    var thRows =  myTable.find("tr:has(th)");
    
    if (thead.length===0){  //if there is no thead element, add one.
        thead = jQuery("").appendTo(myTable);    
    }
    
    var copy = thRows.clone(true).appendTo("thead");
    thRows.remove();
    

    jsFiddle exmaple ​

提交回复
热议问题