如何在回调fancybox中获取链接的属性?

时间:2014-11-02 12:43:54

标签: jquery fancybox fancybox-2

有一个设置fancyBox窗口的代码:

$(".play").fancybox({
        type: 'iframe',
        maxWidth: "90%",
        padding: 0,
        autoCenter: false,
        scrolling: 'no',
        fitToView: false,
        beforeLoad: function () {

 }

带有链接.play的HTML代码:

<a href="#" id="2">Show</a>

如何在回调id="2"中获取属性beforeLoad:

我尝试了this.id

2 个答案:

答案 0 :(得分:3)

解决方案是:$(this.element).attr("id")

答案 1 :(得分:1)

使用:

 var id=$('a').filter(function() {
   return $(this).text().trim() == "Show";
}).attr("id")