【发布时间】:2011-01-04 00:46:45
【问题描述】:
我有这个:
$("a.money").colorbox({href:$("a.money").attr("href")+" div#content"});
这会打开叠加层,但仅包含 #content 选择器中的内容。如果我添加 iframe:true,这将不再有效。有没有办法让它与 iframe 一起使用?
编辑: 我可以让它最接近工作的是这样做:
$("a.money").colorbox({iframe:true, width:700, height:425,
onComplete: function() {
alert('test');
$test = $("#cboxLoadedContent iframe").contents().find("#content").html();
$("#cboxLoadedContent iframe").contents().find("#container").html($test);
}
});
虽然没有警报,但它似乎不起作用,但我研究了一下,我认为我需要使用 .live(),这导致我尝试这样做:
$('a.money').live('click', function() {
url = this.href; // this is the url of the element event is triggered from
$.fn.colorbox({href: url, iframe:true,width:700, height:425,
onComplete: function() {
$test = $("#cboxLoadedContent iframe").contents().find("#content").html();
$("#cboxLoadedContent iframe").contents().find("#container").html($test);
}
});
return false;
});
没用,我仍然需要添加警报才能使其正常工作。
如果您可能想知道我要做什么。网页加载在 iframe 中,所有元素都在 #container 中,因此包括 #header、#sidebars,但我只想在 iframe 中显示 #content。然而,这导致我意识到另一个问题。假设我在没有警报的情况下让它工作,它只适用于那个初始页面。例如,如果我在 iframe 中加载了一个表单,在提交表单后,我将再次看到整个布局,而不仅仅是#content 部分。是否可以在进一步导航时继续仅显示页面的#content 部分?
【问题讨论】: