2013-12-16 107 views
0

當我達到這種情況時,我總是收到錯誤或卡住了,我從數據庫中使用ajax獲取圖像,並且想要在頁眉中顯示它們, 我已添加所有鏈接jQuery動態創建的內容

htlmcon += ' <a rel="example_group" href="data:image/png;base64,' + $(this).find("ImageData").text() + '" title="Lorem ipsum dolor sit amet"><img alt="" src="data:image/png;base64,' + $(this).find("ImageData").text() + '" /></a>'; 

fancy box文件中提到我有記錄準備以下:加載頁面和GETT後

$("a.group").fancybox({ 
    'transitionIn' : 'elastic', 
    'transitionOut' : 'elastic', 
    'speedIn'  : 600, 
    'speedOut'  : 200, 
    'overlayShow' : false 
}); 

到所需的腳本,然後 我我的DIV中寫道:荷蘭國際集團的圖像其表現erorr(未捕獲的類型錯誤:對象[對象的對象]無方法「的fancybox」)

所以我已刪除從該文檔中的fancybox功能準備並將其添加到

$.ready.promise().done(function(){ 

但仍不工作,我也試圖直接調用它後,我得到的圖像,仍然相同得到相同的錯誤未捕獲TypeError:對象[對象對象]沒有方法'fancybox'

請指導我如何調用和在哪裏稱它。

注意我已經在普通頁面中嘗試了它,而不是在它正在工作的動態內容上。

祺....

編輯: 我已經加入此功能可將文件準備好:

$(document).ready(function() { 
      $("#imglist").on("focusin", function() { 
       // /* 
       // * Examples - images 
       // */ 


       $("a[rel=example_group]").fancybox({ 
        'transitionIn': 'none', 
        'transitionOut': 'none', 
        'titlePosition': 'over', 
        'titlePosition': 'outside', 
        'overlayColor': '#000', 
        'overlayOpacity': 0.9, 
        'titleFormat': function (title, currentArray, currentIndex, currentOpts) { 
         return '<span id="fancybox-title-over">Image ' + (currentIndex + 1) + '/' + currentArray.length + (title.length ? ' &nbsp; ' + title : '') + '</span>'; 
        } 
       }); 
      }); 
}); 

所以遺漏的類型錯誤消失了,但的fancybox不工作,但我想也許它亙古不變的走進去$( 「#imglist」)上( 「的focusIn」,函數(){....

而且,這些都是我的引用:

<script src="code.jquery.com/jquery-1.9.1.js"></script>; 
<script src="code.jquery.com/jquery-migrate-1.1.0.js"></script>; 
<script src="JS/jquery.mobile-1.3.2.min.js"></script> 
<script type="text/javascript" src="./fancybox/jquery.mousewheel-3.0.4.pack.js"></script> 
<script type="text/javascript" src="./fancybox/jquery.fancybox-1.3.4.pack.js"></script> 
<link rel="stylesheet" type="text/css" href="./fancybox/jquery.fancybox-1.3.4.css" media="screen" /> 
+0

此錯誤表示您在調用fancybox()方法之前沒有加載fancybox插件。請不要使用下面的語法:'$ .ready.promise()。done(function(){...})' –

+0

[how to bind fancybox to dynamic added element?](http:/ /stackoverflow.com/questions/9081571/how-to-bind-fancybox-to-dynamic-added-element) – JFK

+0

答案http://stackoverflow.com/a/9084293/1055987包括演示。檢查源代碼並與您的比較。另外,請確保您對所有js和css文件的引用都是正確的(請參閱源代碼並單擊每個鏈接的文件以確保您沒有404錯誤) – JFK

回答

0

看起來像你還沒有加載fancybox。

您可以包含以下內容將其包含在您的網頁中。 (以下從CDN加載它)

<script src="cdnjs.cloudflare.com/ajax/libs/fancybox/2.1.5/jquery.fancybox.pack.js" type="text/javascript"></script>