让我先说明一下......我已经引用了这个问题/答案,它似乎包含线索,但我仍然没有看到全貌
Run JQuery in the context of another frame
本质上,index页面的结构是这样的
<html>
<body>
<div class="frames-wrap">
<iframe id="this-iframe" src="location.php">
</iframe>
</div>
</body>
</html>
location.php 然后包含一个框架集(咳咳,这不是我的想法...),它有两个框架,它们是这样设置的...
<frameset cols="350,*">
<frame src="search.php" id="frame_search" name="search"/>
<frame src="edit.php" id="frame_edit" name="edit" />
</frameset>
如果我想在索引页和这些元素之间操作对象,我该怎么做?
我一直认为上下文应该类似于 window.parent.frames[0].document
...我还缺少什么?
最佳答案
前言:除非来自同一域,否则您将无法访问 iframe 内容。
要选择 iframe 中的元素,您可以使用这样的 jQuery 调用
element = $("#this_iframe").contents().find("#frame_search")
关键是使用contents()
函数。参见 Traversing/contents
关于javascript - iframe 中框架的 jQuery/javascript 上下文是什么?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2150327/