JQuery调用iframe子页面函数/对象的方法例子


父页面有个ID为mainfrm、name为Iframe1的iframe,iframe连接b.html,该页面有个函数test

在父页面调用b.html的test方法为:

$("#mainfrm")[0].contentWindow.test();

或者

this.frames["Iframe1"].doQuery();

在当前弹出的子页面中打开另一个打开页面中的函数,例如在弹出的edit.html页面中调用dataList.html页面中的函数test

parent.document.frames["Iframe1"][0].test();

 

////////////////////////////////////////////////////////////////////////////////////

第一、在iframe中查找父页面元素的方法:

$('#id', window.parent.document)

第二、在父页面中获取iframe中的元素方法:

$(this).contents().find("#suggestBox")

第三、在iframe中调用父页面中定义的方法和变量:

parent.method

parent.value

 

iframe里用jquery获取父页面body
 
iframe.html
<html>
<script src='jquerymin.js'>
</script>
<body id='1'>
    <div>it is a iframe</div>
</body>    
<script>
    $(document).ready(
        function()
        {
           
        var c = $(window.parent.document.body) //麻烦的方法: var c = $($(window).eq(0)[0].parent.document).find('body'); ,忘了可以用前面的方法了
            
        alert(c.html());
        }
    );
    
</script>
</html>
View Code

 

 


免责声明!

本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系本站邮箱yoyou2525@163.com删除。



 
粤ICP备18138465号  © 2018-2025 CODEPRJ.COM