使用;不是";在jquery第n个子公式中

使用;不是";在jquery第n个子公式中,jquery,Jquery,我想删除第三、第四、第六、第七、第九等TH。 我想我可以做一些类似的事情: summaryHead.find('tr:first th:nth-child(!3n+2)').remove; 但是它不起作用。 我也试过了 summaryHead.find('tr:first th:nth-child(3n+3)').remove(); summaryHead.find('tr:first th:nth-child(3n+4)').remove(); 这种行为相当奇怪。有没有办法把两个发现结

我想删除第三、第四、第六、第七、第九等TH。 我想我可以做一些类似的事情:

  summaryHead.find('tr:first th:nth-child(!3n+2)').remove;
但是它不起作用。 我也试过了

summaryHead.find('tr:first th:nth-child(3n+3)').remove();
summaryHead.find('tr:first th:nth-child(3n+4)').remove();
这种行为相当奇怪。有没有办法把两个发现结合起来

为清晰起见,我想删除此图像中的所有绿色和红色字段,有时可能会有更多或更少的房间,但每个房间将有3个字段,我想给出第一个房间的字段
colspan 3
,并隐藏两个额外的字段(此处为红色和绿色):

我不确定是否有更好的方法,但你总是可以这样做的

summaryHead.find('tr:first th').filter(':nth-child(3n+3), :nth-child(3n+4)').remove();

如果要保留的是
3n+2
,则可以使用
:not

summaryHead.find('tr:first th:not(:nth-child(3n+2))').remove();

您的第二次尝试不起作用,因为您运行的第二次
find
对已编辑的组有效(上一步中的元素已被删除,因此它不会针对您认为的内容)

您的模式看起来很混乱。你能把它看清楚吗?关上<代码>summaryHead.find('tr:first').find('th:nth child(3n+3),th:nth child(3n+4)).remove()成功!谢谢。@smnbbrv您应该使用
.filter
而不是
.find
,因为您已经选择了
th
元素。@GabyakaG.Petrioli完全正确,谢谢您的建议,但这也会删除第一个子元素。遗憾的是,这是较短的代码。没错,我只是把你的
('tr:first-th:nth-child(!3n+2)
翻译成一个工作版本。