2012-03-05 30 views
0

後,我已經創建的fancybox形式:的fancybox鏈接不工作阿賈克斯

$("a.productForm").fancybox({ 
    'hideOnOverlayClick' : true, 
    'modal' : true, 
    'hideOnContentClick' : false, 
    'showCloseButton' : false, 
    'padding' : 0, 
    'transitionIn' : 'elastic', 
    'transitionOut' : 'elastic', 
    'autoScale'  : false, 
    'autoDimensions': false, 
    'frameWidth': 717, 
    'frameHeight': 900, 
    'overlayOpacity': 0.4, 
    'centerOnScroll' : false, 
    'type': 'ajax', 
    'ajax': { 
    dataFilter: function(data) { 
     return $(data).find('#form_wrapper')[0];} 
} 
}); 

可以在this頁它是如何工作看。

要查看我的fancybox形式,按請鏈接:

enter image description here

正如你可以看到所有的作品只是在這個頁面正常,但我的代碼在頁面,產品加載使用Ajax不會工作。你可以看到this頁面。

當你在這個頁面按下綠色按鈕,fancybox只是不會出現,而是直接進入鏈接。什麼可能是錯的?

也許我必須應用fancbox代碼到這個鏈接後,它加載白衣阿賈克斯?

+0

我曾經用jquery 1.4中的livequery插件來解決這個問題。但我認爲jQuery 1.7已經有了更好的選擇。 – Marnix 2012-03-05 14:07:09

回答

2

在收到html數據並添加到dom後,您需要在ajax成功回調中執行$(「a.productForm」)。fancybox(...)。

這裏有一個簡單的例子:

$.ajax({ 
    url: "test.html", 
    success: function(data){ 
    $('#newest_desc').html(data); // Here you insert data which I'm expecting to be a string with html into the tab with the id "newest_desc". I got that from your website. Not sure if it's correct though. 
    $("a.productForm").fancybox(...) // Here is where you call the fancybox function because now you know that the element a.productForm is available. 
    } 
}); 
+0

你能告訴我我該怎麼做? – iKaspars 2012-03-05 14:17:05

+0

@iKaspars我已經添加了一個簡單的例子。讓我知道它是否有幫助。 – 2012-03-05 15:08:55

+0

謝謝,我會環顧四周。唯一的問題是我沒有創建該插件來獲得帶有Ajax的產品。那樣的話,我認爲很難找到他們用ajax獲得產品的代碼部分。不過謝謝。 – iKaspars 2012-03-05 15:13:53

0

你似乎有在JavaScript的一些錯誤。這會導致鏈接被瀏覽器所遵循。

如果您還沒有安裝Firebug,請啓用控制檯,然後單擊「persist」。這樣,當瀏覽器更改頁面時,錯誤不會消失,您將能夠看到錯誤。