Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/jquery/85.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
删除表列和标题,使用jquery删除具有行跨度和列跨度标题的表_Jquery - Fatal编程技术网

删除表列和标题,使用jquery删除具有行跨度和列跨度标题的表

删除表列和标题,使用jquery删除具有行跨度和列跨度标题的表,jquery,Jquery,我有一个表,需要使用jquery删除它的列。使用它,但它会删除所有标题,但我希望只删除第一行标题 <table border="2" style="border-collapse:collapse;"> <tr> <tr> <th rowspan="2">#</th> <th rowspan="2">A</th> <t

我有一个表,需要使用jquery删除它的列。使用它,但它会删除所有标题,但我希望只删除第一行标题

   <table border="2" style="border-collapse:collapse;">
    <tr>
    <tr>
           <th rowspan="2">#</th>
           <th rowspan="2">A</th> 
           <th rowspan="2">B</th>
           <th rowspan="1" colspan="3">C</th>
    </tr>
<tr>

           <th>C-1</th>
           <th>C-2</th> 
           <th>C-3</th>
</tr>

<tr>

           <td>CONTENT</td>
           <td>CONTENT</td>
           <td>CONTENT</td>        
           <td>CONTENT</td>
           <td>CONTENT</td> 
           <td>CONTENT</td> 
</tr>


</table>

它删除了TH-A及其列内容,但也删除了
:C-2,请帮助。

首先,您的代码顶部有一个额外的
tr
。将其移除,然后可以使用 选择器来完成您想要的这种特定html结构

$('tr td:nth-child(2), tr:first-child > th:nth-child(2)').remove();​
解释

排除
C-2
的选择器是
tr:first child>th:nth child(2)
。它告诉jQuery的事情是
找到第一个tr
,然后
找到第二个tr
是指查找
th
中的
tr
的子项。由于
C-2
位于第二个
tr
位置,因此被排除在外。如果这对你有意义,请告诉我。我不太擅长写作


这会更改所需元素的颜色。在您的代码中使用remove。

先生,它在演示中起作用,但在我的代码中它不起作用。请删除html代码顶部的额外
tr
。或者请粘贴您的html代码并共享链接,以便我可以查看是否可以在其中指定表ID?是的,当然可以。只需在每个选择器的开头添加
#TABLE_ID
。然后它将仅在该表中搜索。:)让我们
$('tr td:nth-child(2), tr:first-child > th:nth-child(2)').remove();​