2017-10-17 142 views

回答

2

原始元素被存儲到opts.$orig(定製),這是你將如何獲得ID:

afterLoad: function(instance, current) { 
    alert(current.opts.$orig.attr("id")); 
} 

https://jsfiddle.net/3bfcrstc/5/

+0

謝謝你這麼多,它的工作原理。 –

0

要獲得點擊的元素的idafterLoad事件處理程序可以從$lastFocus對象獲得context作爲instance參數返回,就像這樣:

$(".cerrar_actividad").fancybox({ 
 
    afterLoad: function(instance, current) { 
 
    alert($(instance.$lastFocus.context).prop("id")) 
 
    } 
 
});
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/fancybox/3.1.25/jquery.fancybox.min.css" /> 
 
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script> 
 
<script src="https://cdnjs.cloudflare.com/ajax/libs/fancybox/3.1.25/jquery.fancybox.min.js"></script> 
 

 
<a id="image1" rel="gallery" class="cerrar_actividad" href="https://www.youtube.com/watch?v=6s-a7Xz_Qqc"><img src="http://fancyapps.com/fancybox/demo/1_s.jpg" alt="" /></a> 
 
<a id="image2" rel="gallery" class="cerrar_actividad" href="https://www.youtube.com/watch?v=6s-a7Xz_Qqc"><img src="http://fancyapps.com/fancybox/demo/1_s.jpg" alt="" /></a>