我该如何使用jQuery与 iframe
协作?获取并传递 iframe
中的变量到 body
,再从 body
传递至 iframe
。下面是我的示例代码,如何让 iframe
中的按钮点击事件对 body
中的 #test
生效?还有,如何获取 iframe
中的变量 x?
<body>
var x = "whatever";
<div id"test"></div>
<iframe width="200px" height="200px" src="page.html"></iframe>
</body>
在page.html文件中,我有以下内容:
<button>clickme</button>
<script>
var elm = $('<span>content</span>');
elm.appendTo('#test')
</script>