jQuery 框架内元素的选择器(具有相同的原点)

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/6473557/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-26 20:55:53  来源:igfitidea点击:

Selector for element inside a frame (with same origin)

jqueryjquery-selectorsframes

提问by priyank

I have a webpage with the following structure:

我有一个具有以下结构的网页:

<html>
<head>...</head>
<frameset>
<frame name="frame1" src="/index.jsp"/>
<frame name="frame2" src="/blank.jsp"/>
</frameset>
</html>

index.jspcontains:

index.jsp包含:

<html>
<head>...</head>
<body>
... <div id="test">test is here</div> ...
</body>
</html>

I need a jQuery selector to directly access div#test. So far I've only been able to write it like this: $(frames[0].document.body)...or this: $("frame[name='frame1']"). But I have a template which requires me to write my selector inside $("here only"). So I can't use .find()or other functions.

我需要一个 jQuery 选择器来直接访问div#test. 到目前为止,我只能这样写:$(frames[0].document.body)...或这样:$("frame[name='frame1']")。但是我有一个模板,需要我在里面写我的选择器$("here only")。所以我不能使用.find()或其他功能。

回答by Matthew Manela

Try:

尝试:

$("div#test", $("#someIFrame").contents())

回答by priyank

yeah I got it. thanks.

是的,我明白了。谢谢。

This is what I wrote.

这是我写的。

$("div[id='test'] > span",frames['frame1'].document).text()