如何从父文档访问 iframe 内的元素? [英] how to access the element inside iframe, from parent document?

查看:35
本文介绍了如何从父文档访问 iframe 内的元素?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

function contents_nb(name, height) {1. document.getElementById('contents_iframe').height = height+'px';2. var $currentIFrame = $('#contents_iframe');3. $currentIFrame.contents().find(".wrap_contents").hide();4. $currentIFrame.contents().find(".greetings").fadeIn(2500);}

这是我的 jquery 语法.

no.1 ~ 3,效果很好.

但是第 4 行,它不起作用.

iframe 中 html 文档的结构是...

<div class="wrap_contents"><div class="问候语">

<div class="operational_philosophy">

</html>

是什么原因?什么原因导致这个问题?

父 html 文档的语法是..

<iframe id="contents_iframe"></iframe>

有什么问题??为什么在class里面找不到class?

解决方案

您可以使用 jquery contents() 函数来访问/查找元素,

$("#iframeID").contents().find("#contentID");

function contents_nb(name, height) {
    1. document.getElementById('contents_iframe').height = height+'px';
    2. var $currentIFrame = $('#contents_iframe'); 
    3. $currentIFrame.contents().find(".wrap_contents").hide();
    4. $currentIFrame.contents().find(".greetings").fadeIn(2500);
}

this is my jquery syntax.

no.1 ~ 3, it works well.

but line no.4, it doesn't work.

structure of html document inside iframe is ...

<body>
    <div class="wrap_contents">
        <div class="greetings">
        </div>
        <div class="operational_philosophy">
        </div>
    </div>
    </body>
    </html>

what is the reason? what causes this problem?

and syntax of the parent html document is..

<iframe id="contents_iframe"></iframe>

what is the problem?? why can not find class inside class?

解决方案

You may used jquery contents() function to access/find the elements,

$("#iframeID").contents().find("#contentID");

这篇关于如何从父文档访问 iframe 内的元素?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
前端开发最新文章
热门教程
热门工具
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆