我尝试访问由jquery colorbox插件生成的iframe的内容几个小时没有成功。使用jquery访问colorbox Iframe内容
继承人我的代码:
$(".ListView li a").colorbox({
iframe:true,
width: "50%",
height: "50%",
opacity: 0.5,
onComplete: function() {
alert("complete");
$("iframe").contents().find("p").css("color","#f00");
}
});
它加载一个文件并显示它。如此精细。当iframe加载完成时,还会引发警报消息。但我无法通过jquery选择器访问框架内的元素。 iframe中的所有p元素都不会发生任何变化。
无论
if($("iframe").contents().length > 0)
{
alert("exists");
}
也不
if($("iframe").length > 0)
{
alert("exists");
}
是成功的。页面上没有其他iframe,我也尝试插入类名称。
对于“正常”的iframe,直接插入到html中而不是由colorbox生成,我的函数正在工作。
谢谢产生
代码:
<div id="colorbox" class="" style="display: block; padding-bottom: 50px; padding-right: 50px; top: 128px; left: 476px; position: absolute; width: 902px; height: 207px;">
<div id="cboxWrapper" style="height: 257px; width: 952px;">
<div>
<div style="clear: left;">
<div id="cboxMiddleLeft" style="float: left; height: 207px;"></div>
<div id="cboxContent" style="float: left; width: 902px; height: 207px;">
<div id="cboxLoadedContent" style="display: block; width: 902px; overflow: auto; height: 187px;">
<iframe class="cboxIframe" frameborder="0" name="cbox1334265249803" src="qtest.html">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<body>
<a href="#">Link</a>
<p>Formatted Text</p>
</body>
</html>
</iframe>
</div>
<div id="cboxLoadingOverlay" style="float: left; display: none;"></div>
<div id="cboxLoadingGraphic" style="float: left; display: none;"></div>
<div id="cboxTitle" style="float: left; display: block;"></div>
<div id="cboxCurrent" style="float: left; display: none;"></div>
<div id="cboxNext" style="float: left; display: none;"></div>
<div id="cboxPrevious" style="float: left; display: none;"></div>
<div id="cboxSlideshow" style="float: left; display: none;"></div>
<div id="cboxClose" style="float: left;">close</div>
</div>
<div id="cboxMiddleRight" style="float: left; height: 207px;"></div>
</div>
<div style="clear: left;">
</div>
<div style="position: absolute; width: 9999px; visibility: hidden; display: none;"></div>
</div>
<div class="ui-dialog ui-widget ui-widget-content ui-corner-all ui-draggable" style="display: none; z-index: 1000; outline: 0px none;" tabindex="-1" role="dialog" aria-labelledby="ui-dialog-title-box-trash-dialog">
非常感谢! Google搜索“完整的colorbox”后,我发现这个网页:http://groups.google。com/group/colorbox/browse_thread/thread/77e89cc514d43abf 你在哪里解释给别人。现在它真棒。 – simonheinrich 2012-04-14 17:15:05