Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/jquery/81.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 如何获取除第一行以外的表格Html_Javascript_Jquery_Html Table - Fatal编程技术网

Javascript 如何获取除第一行以外的表格Html

Javascript 如何获取除第一行以外的表格Html,javascript,jquery,html-table,Javascript,Jquery,Html Table,我有一个表,并希望得到的HTML没有它的第一行 我知道我可以做到这一点: $('#mytable tr:first').remove(); var tableHtml = $('#mytable').html(); 但通过这种方式,我的表将改变,它的第一行将永久删除 如何在不更改表格的情况下执行此操作?使用:not(:type的第一个)选择标记,但第一个标记除外 var rows = $('#mytable tr:not(:first-of-type)'); 是的,有办法 首先,需要克隆表

我有一个表,并希望得到的HTML没有它的第一行

我知道我可以做到这一点:

$('#mytable tr:first').remove();
var tableHtml = $('#mytable').html(); 
但通过这种方式,我的表将改变,它的第一行将永久删除

如何在不更改表格的情况下执行此操作?

使用
:not(:type的第一个)
选择
标记,但第一个标记除外

var rows = $('#mytable tr:not(:first-of-type)');
是的,有办法

首先,需要克隆表元素:

var clone = $("#mytable").clone();
然后,删除第一行并获取HTML:

console.log(clone.find("tr:first").remove().end().html());
//                find first row then remove |      |
//                                           |      +--------+
//                                      go back to parent    |
//                                                           |
//                                                       get HTML

它给我行数组,但我想要整个html字符串(带table、thead、tbody等)