3
如何使用jQuery測試某個元素是否駐留在iFrame中,如果存在,如何選擇該iFrame?如何使用jQuery測試元素是否駐留在iFrame中?
如何使用jQuery測試某個元素是否駐留在iFrame中,如果存在,如何選擇該iFrame?如何使用jQuery測試元素是否駐留在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;
});
它應該比接受的答案快。
我不知道iframe。如果沒有ID,該怎麼辦?從元素開始,看看是否駐留在iFrame中。 –
爲什麼投票給這個? – ShankarSangoli
您將有一些方法來查找iframe。檢查我編輯的答案。 – ShankarSangoli