gpt4 book ai didi

javascript - JQuery .addclass 到找到文本的表 元素

转载 作者:数据小太阳 更新时间:2023-10-29 04:59:28 24 4
gpt4 key购买 nike

我正在为一些报告表设置主题,但无权访问模板。

到目前为止,我有这段代码,它最终将“我的类”添加到报告表中的每个 TR 元素。但是,我只想将该类添加到找到文本的表行 TR 中。我在想我需要更多的代码来做到这一点。以下是我迄今为止尝试过的一些方法:

if ($('#report-area table tr:contains("Name")', this).length > 0) {
$("#reportArea table tr", this).addClass("my-class");
}

我也试过:

if ($('#report-area table tr:contains("Name")', this).length > 0) {
$(this).addClass("my-class");
}

...但这也不起作用。

最佳答案

只需使用没有绒毛的选择器:

$('#report-area tr:contains("Name")').addClass('my-class');

http://api.jquery.com/contains-selector/

关于javascript - JQuery .addclass 到找到文本的表 <tr> 元素,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8056509/

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