Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/jquery/76.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/delphi/9.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
如何使用jQuery测试元素是否驻留在iFrame中?_Jquery - Fatal编程技术网

如何使用jQuery测试元素是否驻留在iFrame中?

如何使用jQuery测试元素是否驻留在iFrame中?,jquery,Jquery,如何使用jQuery测试元素是否驻留在iFrame中,如果驻留在iFrame中,如何选择该iFrame?试试这个,它会对您有用 var requiredIframe; $("iframe").each(function(){ if($(this).contents().find("elementYouAreLookingFor").length){ requiredIframe = $(this); return false; } }); 这就行了 var elem

如何使用jQuery测试元素是否驻留在iFrame中,如果驻留在iFrame中,如何选择该iFrame?

试试这个,它会对您有用

var requiredIframe;
$("iframe").each(function(){
  if($(this).contents().find("elementYouAreLookingFor").length){
     requiredIframe = $(this);
     return false;
  }
});
这就行了

var elementDocument = $("#your-element").prop("ownerDocument");

var iframeOwner = $("iframe").filter(function() {
                      return this.contentDocument == elementDocument;
                  });

这应该比公认的答案快。

我不知道答案。如果它没有id怎么办?从元素开始,看看是否驻留在iFrame中。您将有一些方法找到iFrame。检查我编辑的答案。