如何获取在 onComplete 中打开 Fancybox3 的 link 的 ID?

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

我在 Whosebug 上的其他问题中看到了这个问题的解决方案,但其中 NONE 有效。

我正在尝试获取点击打开 Fancybox 的 link 的内部文本:

$("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
              });

});

每次都只有 returns 最后一个 a.turnDateLink. 的 innerText!呃

请记住,我想对此使用 fancybox 分组。

查看 Fancybox 文档以了解分组:http://fancyapps.com/fancybox/3/docs/#usage

If you have a group of items, you can use the same attribute data-fancybox value for each of them to create a gallery. Each group should have a unique value:

试试 this.Change $( "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
                  });
    });

检查有关事件的文档 - 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 );

}