我想通过beforeLoad回调获取当前活动fancybox链接的类别。获取Fancybox 2回调中有效项目的类别
HTML例如:
<a href="example.png" class="lightbox pdf-opening">Link</a>
<a href="example2.png" class="lightbox pdf-closing">Link</a>
的jQuery /的fancybox代码:
$(document).ready(function() {
$(".lightbox").fancybox(
{
beforeLoad: function(){
var pdf_type_string = $(".lightbox").eq(this.index).attr('class').split(' ').slice(-1);
var test = pdf_type_string.toString();
var pdf_type = test.substr(4);
alert(pdf_type);
},
title: '<a class="lightbox_link_to_tickets" href="/your-visit/booking-online/">Book your tickets here</a>',
type: 'image'
}
);
});
单击第二个链接,(理论上我)应该返回1,即使this.index总是返回0,当点击第二个链接...
任何帮助非常感谢。
保罗
解决方案
对我来说,解决办法是如下:
$(document).ready(function() {
$(".lightbox").fancybox(
{
beforeLoad: function(){
var pdf_type_object = $(this.element).attr('class').split(' ').slice(-1);
var pdf_type_string = pdf_type_object.toString();
var pdf_type = pdf_type_string.substr(4);
this.title = '<a class="lightbox_link_to_tickets" href="/your-visit/booking-online/">Book your tickets here</a> - <a class="lightbox_link_to_tickets" href="/inc/images/your-visit/timetables-and-fares/'+pdf_type+'.pdf">Downloadable PDF</a>';
},
type: 'image'
}
);
});
干杯!这适用于我!我有一种感觉this.index是不是我正在寻找... – PaulSkinner