隐藏iframe内的内容? [英] Hide content inside iframe?

查看:111
本文介绍了隐藏iframe内的内容?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这是我的情况。

我有一个名为iframe.html的文件。其中有代码在下面,

I have a file called iframe.html. which has code in below,

<!DOCTYPE html>
<html lang="eng">
    <head>
        <meta charset="UTF-8"/>
        <title>Pluign Development</title>

        <script src="js/jquery-1.11.0.js" type="text/javascript"></script>
    </head>

    <body>

        <iframe id="abc" src="test.html"></iframe>
        <div id="sub">click</div>
    </body>

    <script src="js/script-22.js" type="text/javascript"></script>
</html>

我有test.html文件。其中有代码在下面,

and i have test.html file. which has code in below,

<!DOCTYPE html>
<html lang="eng">
    <head>
        <meta charset="UTF-8"/>
        <title>Pluign Development</title>

    </head>

    <body>

        <div id="red">prasanga karunanayake </div>
    </body>


</html>

这里是我试过的js代码,

here is js code what i have tried,

(function($){ 

    var fire = {
        init:function(){
            $('#sub')
            .on('click', function(){
                $('#red', parent.document).css('display','none');
            });
        }
    };
    fire.init();

}(jQuery));

这是我的情况。

i需要隐藏test.html文件中的< div id =red> prasanga karunanayake< / div> 。点击< div id =sub>点击< / div> ,然后隐藏test.html中的html内容。

i need to hide <div id="red">prasanga karunanayake </div> which is in the test.html file. if i click <div id="sub">click</div> then hide html content which is in the test.html.

我非常困惑,感谢您的帮助。

I am pretty much confused,Your help is appreciated.

推荐答案

您可以使用这样:

You can use .contents() this way:

$('#abc').contents().find('#red').hide();






另一件事是,在页面响应进入浏览器时运行的闭包中。因此,这种代码更改可能无法工作。


Another thing is, As you have wrapped your code in a closure which runs as page response gets in the browser. So it might be possible that this code change would not work.

相反,我建议你也为此设置一个dom ready块:

Instead i suggest you to put a dom ready block also for this:

(function($){ 
    $(function(){ // <---add this block from here to
      var fire = {
        init:function(){
            $('#sub').on('click', function(){
                $('#abc').contents().find('#red').hide();
            });
        }
      };
      fire.init();
  }); //<----here
}(jQuery));

这篇关于隐藏iframe内的内容?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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