gpt4 book ai didi

javascript - 在其他 JQuery 对象中查找 JQuery 对象

转载 作者:行者123 更新时间:2023-11-28 20:01:44 25 4
gpt4 key购买 nike

抱歉我的英语不好

我有html

<noindex>
<h1>This is h1 in noindex</h1>
<div>
<h1>This is h1 in noindex and in div</h1>
<div>
<h1>This is h1 in noindex and in div>div</h1>
</div>
</div>
<h2>This is h2 in noindex</h2>
</noindex>

<h1>This is h1</h1>
<h2>This is h2</h2>

然后,在js中

var all_h1 = $('h1');
var all_h2 = $('h2');
all_h1.each(function()
{
if($($(this),'<noindex>'))
{
//do somthing only with $(this)
}
});

我知道,这不行。我使用 has()、find()、$.contains 等,但它不起作用。如何在其他jq.object中搜索某个jq.object?

最佳答案

你可以这样尝试

all_h1.each(function()
{
if($(this).closest('noindex').length > 0)
{
//it is contained inside of <noindex>
}
});

关于javascript - 在其他 JQuery 对象中查找 JQuery 对象,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21559304/

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