gpt4 book ai didi

JQuery初学者: :has for direct descendants only

转载 作者:行者123 更新时间:2023-12-01 07:03:10 24 4
gpt4 key购买 nike

假设树结构如下:(丑陋的遗留布局,抱歉)

<tr>                          (1) dont want to select this one  
<td>
<table>
<tr> (2) not a "special" td, dont select
<td.normal>
<tr> (3) this is what I want to select
<td.special>
<tr>
<td.normal>

我想选择具有特殊类 td 的 tr 作为直接后代,即只有(2),而不是(3)[其td不特殊],也不是(1)[特殊td不是直系后代而是“孙子”]

我试过了

$("tr:has(td.special)");

但这给了我 (1) 和 (2),因为 :has 的意思是“在我所有的后代中都有某个地方”。

我需要的是类似 :has 的东西,但意思是“在我的直系 child 中”。

或者,向上横向的方法,例如“仅选择当前所选元素的父元素”。

很抱歉问了这个简单的问题,但我似乎在 API 文档中找不到它。

最佳答案

您尝试过 $("td.ptextno:contains('Betreuung')").parent() 吗?

编辑:看起来问题的示例已更改...尝试 $("td.special").parent()
编辑2:正如你所知,有关遍历的文档在这里:http://docs.jquery.com/Traversing

关于JQuery初学者: :has for direct descendants only,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/447525/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com