在iframe和parent之间传递jquery变量 [英] Pass jquery variables between iframe and parent

查看:93
本文介绍了在iframe和parent之间传递jquery变量的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何使用jQuery和 iframe 。从 iframe 获取并传递 var body 并从正文 iframe 。我有以下例子。如何点击 iframe 中的按钮,使其在正文 上生效#测试。如何在iframe中准备var x。

How can I work with jQuery and iframe. Get and pass var from iframe to body and from body to iframe. I have the following example. How can I click the button in iframe and make it take effect on the the body #test. How about ready var x in iframe.

<body>
var x = "whatever";
<div id"test"></div>
<iframe width="200px" height="200px" src="page.html"></iframe>
</body>

在page.html里面我有

Inside page.html i have

<button>clickme</button>
<script>
var elm = $('<span>content</span>');
    elm.appendTo('#test')
</script>


推荐答案

$("#myid", top.document); 

$("#myid", parent.document.body); 

这将允许您访问IFRAME的容器

This will give you access to the container of the IFRAME

按照: http://groups.google.com / group / jquery-en / browse_thread / thread / 5997ef4a60a123af

这篇关于在iframe和parent之间传递jquery变量的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆