2017-04-20 21 views
0

我想在羽毛模態圖像下添加標題。我嘗試使用下面的代碼來做到這一點,就像這裏建議的其他許多帖子一樣,但它不起作用。如何將標題/大拇指向上或向下添加到羽毛燈

$.featherlightGallery.prototype.afterContent = function() { 
      var caption = this.$currentTarget.find('img').attr('alt'); 
      this.$instance.find('.caption').remove(); 
      $('<div class="caption">').text(caption).appendTo(this.$instance.find('.featherlight-content')); 
    } 

相反,我在控制檯得到了以下錯誤:

Uncaught TypeError: Cannot read property 'prototype' of undefined 
at main.js:62 

featherlight.min.js:8 Featherlight: no content filter found (no target specified) 

這裏是我如何插入圖片到我的網頁。我的計劃是在模態圖像下面包括一個大拇指,我認爲至少讓alt標籤正確顯示將是一個很好的第一步。如果任何人都可以幫助插入一個鏈接/圖像,而不是一個更好的alt標題!任何幫助是極大的讚賞!

JAVASCRIPT

function putImages(){ 

if (ajaxCall.readyState==4){ 

    if(ajaxCall.responseText){ 
     // to separate the file names, with semicolons 
     var resp = ajaxCall.responseText; 
     var files = resp.split(";"); 
     // check if string isn't empty and add a thumbnail 
     for(var i = 0; i < files.length; i++){ 

      if(files[i] != ""){ 

       document.getElementById("gallery").innerHTML += '<img class="myImg" src="/img/'+files[i]+'" width="198" height="198" alt="test" data-featherlight="/img/'+files[i]+'" />'; 
       picCount++; 

       } 
      } 
     } 
    } 
} 

HTML

<div class="container"> 
     <!-- Image Gallery --> 
     <div class="row"> 
     <div class="col-xs-12" id="gallery"> 

     </div> 
     </div> 
    </div> 

回答

0

該錯誤消息告訴你,$.featherlightGalleryundefined。你沒有正確加載羽毛畫廊,或者只是使用羽毛燈,那麼這是你應該改變的選項。

+0

因此,我將'$ .featherlightGallery'改爲'$ .featherlight',並得到類似的錯誤'Uncaught TypeError:無法讀取未定義的屬性'prototype'和'Featherlight:未找到內容過濾器(未指定目標) .'點擊圖片調出燈箱。燈箱似乎工作正常,所以我真的不知道這是最後一個錯誤是關於什麼。我真正能看到的唯一問題是缺少標題。這可能是因爲我沒有使用''標籤嗎? – migs

相關問題