我必须使用 tbody 的第一行创建一个 thead。我无法完全控制标记,因此我使用 jQuery 来执行此操作。
我已经成功地使用了一些借用的脚本,但是当我向页面添加多个表格时,第一行似乎在下表中重复
我想我需要定位父表,通常我会给每个表一个 ID,但我不能,因为这些是为我生成的。
可以在这个 fiddle http://jsfiddle.net/FGH6B/ 上看到正在发生的事情的示例。
我当前的jquery如下
jQuery("document").ready( function() {
var mytable = $("table");
mytable.prepend(document.createElement('thead'));
$("table thead").append($("tbody tr:eq(0)"));
});
最佳答案
试试这个:
$("document").ready( function() {
$('table').each(function(){
$(this).prepend('<thead></thead>')
$(this).find('thead').append($(this).find("tr:eq(0)"));
})});
<强> Working Demo
关于jquery - 仅针对父表添加 thead 并从 tbody 插入第一个 tr,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23291138/