簡體   English   中英

如何獲取在onComplete中打開Fancybox3的鏈接的ID?

[英]How to get ID of link that opened Fancybox3 within onComplete?

我在其他關於stackoverflow的問題中看到了看起來可能是該問題的解決方案,但是沒有一個起作用。

我試圖獲取單擊以打開Fancybox的鏈接的內文:

$(“ a.turnDateLink”)。each(function(){

  var that = $(this); $( "a.turnDateLink" ).fancybox({ 'type': 'modal', 'onComplete': function() { var currentday = $(that).text(); console.log(currentday); }, 'afterClose': clearCurrentDay, 'fullScreen' : false }); 

});

它僅返回最后一個a.turnDateLink.的innerText a.turnDateLink. 每次! 啊。

請記住,我想與此一起使用fancybox分組。

請參閱Fancybox文檔以了解分組: http ://fancyapps.com/fancybox/3/docs/#usage

如果您有一組項目,則可以為每個項目使用相同的屬性data-fancybox值來創建畫廊。 每個組應具有唯一的值:

查看有關事件的文檔-http://fancyapps.com/fancybox/3/docs/#events

第一個示例包含有用的提示,包括如何查找被點擊的元素:

onComplete: function( instance, slide ) {

    // Tip: Each event passes useful information within the event object:

    // Object containing references to interface elements
    // (background, buttons, caption, etc)
    // console.info( instance.$refs );

    // Current slide options
    // console.info( slide.opts );

    // Clicked element
    // console.info( slide.opts.$orig );

    // Reference to DOM element of the slide
    // console.info( slide.$slide );

}

像這樣嘗試。將$( "a.turnDateLink" )更改為that

$("a.turnDateLink").each(function() {

                  var that = $(this);

                  that.fancybox({
                      'type': 'modal',
                      'onComplete': function() {
                          $("#currentday").html('');

                          var currentday = that.text();
                          console.log(currentday);
                      },
                      'afterClose': clearCurrentDay,
                      'fullScreen' : false
                  });
    });

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM