【问题标题】:jQuery - iframe inside iframe - ready vs loadjQuery - iframe 内的 iframe - 准备好与加载
【发布时间】:2016-08-24 15:48:28
【问题描述】:

假设我有以下内容:

default.asp:

<iframe src="frameOne.asp" id="myframeOne"></iframe>

frameOne.asp:

<iframe src="frameTwo.asp" id="myframe"></iframe>

frameTwo.asp:

<div id="hello">Test text</div>

为什么以下不起作用(#1):

$("#myframeOne").load(function () {
         $('#myframeOne').contents().find('#myframeTwo').load(function(){
             $('#myframeOne').contents().find('#myframeTwo').contents().find('#hello').css('background-color','blue');
         });
    });

这确实应用了 CSS?(#2):

 $("#myframeOne").load(function () {
             $('#myframeOne').contents().find('#myframeTwo').ready(function(){
                 $('#myframeOne').contents().find('#myframeTwo').contents().find('#hello').css('background-color','blue');
             });
        });

而这个没有(#3):

$("#myframeOne").ready(function () {
                 $('#myframeOne').contents().find('#myframeTwo').ready(function(){
                     $('#myframeOne').contents().find('#myframeTwo').contents().find('#hello').css('background-color','blue');
                 });
            });

据我了解,.load 会等到 iframe 的内容被加载,所以我不太明白为什么它在框架上的行为不同(为什么它在应用在外框架上时有效,但在内框架中无效)。

【问题讨论】:

  • 你用的是哪个版本的jQuery?

标签: javascript jquery html iframe


【解决方案1】:

对于 iframe,我总是使用加载功能。我也遇到了 ready 函数的问题,所以尝试使用 load 函数。

【讨论】:

    猜你喜欢
    • 2015-07-12
    • 1970-01-01
    • 1970-01-01
    • 2012-02-15
    • 2017-07-05
    • 2011-06-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多