假设我有以下内容:
默认.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 的内容加载完毕,所以我不太明白为什么它在框架上的行为不同(为什么它在应用于外部框架时有效,但不适用于内部框架) )。
最佳答案
对于 iframe,我总是使用加载函数。我也遇到了就绪函数的问题,所以尝试使用加载函数。
关于javascript - jQuery - iframe 内的 iframe - 就绪与加载,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39090968/