Javascript 在其他JQuery对象中查找JQuery对象

Javascript 在其他JQuery对象中查找JQuery对象,javascript,jquery,html,Javascript,Jquery,Html,对不起,我英语不好 我有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> &

对不起,我英语不好

我有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>

这是诺因德的h1
这是noindex和div中的h1
这是noindex和div>div中的h1
这是诺因德斯的h2
这是h1
这是h2
然后,在js中

var all_h1=$('h1');
var all_h2=$('h2');
所有_h1.每个(函数()
{
如果($($(本),'')
{
//仅使用$(此)执行某些操作
}
});
我知道,这不是工作。我使用has()、find()、$.contains和其他,但它不起作用。如何在其他jq.object中搜索某个jq.object?

您可以这样尝试

all_h1.each(function()
{
  if($(this).closest('noindex').length > 0)
  {
    //it is contained inside of <noindex>
  }
});
all_h1.每个(函数()
{
if($(this).closest('noindex')。长度>0)
{
//它包含在
}
});
您可以这样尝试

all_h1.each(function()
{
  if($(this).closest('noindex').length > 0)
  {
    //it is contained inside of <noindex>
  }
});
all_h1.每个(函数()
{
if($(this).closest('noindex')。长度>0)
{
//它包含在
}
});
您可以这样尝试

all_h1.each(function()
{
  if($(this).closest('noindex').length > 0)
  {
    //it is contained inside of <noindex>
  }
});
all_h1.每个(函数()
{
if($(this).closest('noindex')。长度>0)
{
//它包含在
}
});
您可以这样尝试

all_h1.each(function()
{
  if($(this).closest('noindex').length > 0)
  {
    //it is contained inside of <noindex>
  }
});
all_h1.每个(函数()
{
if($(this).closest('noindex')。长度>0)
{
//它包含在
}
});

我知道,该标记无效。我知道,该标记无效。我知道,该标记无效。我知道,该标记无效。@user3271784所以您想检查noindex的直接子级。对。?我想要检查包含一些(或其他)。@user3271784所以您想要检查noindex的直接子项。对。?我想要检查包含一些(或其他)。@user3271784所以您想要检查noindex的直接子项。对。?我想要检查包含一些(或其他)。@user3271784所以您想要检查noindex的直接子项。对。我要支票包含一些(或其他)。