简体   繁体   English

如何从父文档访问iframe中的元素?

[英]how to access the element inside iframe, from parent document?

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. 这是我的jQuery语法。

no.1 ~ 3, it works well. 1〜3号,效果很好。

but line no.4, it doesn't work. 但是第4行,它不起作用。

structure of html document inside iframe is ... iframe中的html文档结构是...

<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.. 父html文档的语法是

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

what is the problem?? 问题是什么?? why can not find class inside class? 为什么在课内找不到课?

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

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM