我使用Fancybox(http://fancybox.net)來彈出一個iFrame。爲了做到這一點,我創建一個設置爲「item_pop」作爲這樣一類的鏈接:使用jQuery追加動態生成的html與Fancybox不兼容
<div id="events">
<a href="http://www.example.com" class="item_pop">My Link</a>
</div>
然後我有一些JavaScript的支持此頁腳:
jQuery(".item_pop").fancybox({
'width' : 900,
'height' : 500,
'autoDimensions' : true,
'autoScale' : true,
'transitionIn' : 'elastic',
'titleShow' : false,
'transitionOut' : 'elastic',
'centerOnScroll' : true,
'type' : 'iframe'
});
好了,這一切都可以順利運作。問題是,我使用jQuery動態創建這樣的附加鏈接,那麼:
jQuery(document).ready(function(){
update_seconds = 20;
update_duration = update_seconds * 1000;
window.setInterval(reload_events, update_duration);
});
function reload_events()
{
jQuery.post("http://www.example.com", {type:'any'}, function(data){
var events = eval(data);
var html = '';
for(var i=0; i<events.length; i++){
var evt = events[i];
html += '<a href="http://www.example.com" class="item_pop">My Link</a>';
}
jQuery('#events').children().remove();
jQuery('#events').append(html);
});
}
這實際上顯示的鏈接,屏幕,但是當你點擊他們,他們不彈出的iFrame。相反,他們將預期頁面作爲新頁面打開,而不是作爲現有頁面內的iFrame。
任何想法?乾杯
嗨,謝謝。在HTML輸出到屏幕後,我使用了你的建議再次運行Fancybox調用,並且它工作得很好。乾杯 – 2010-08-26 13:21:16