2010-08-03 57 views
1

我需要知道哪些具體類的錨(觸發fancybox)必須做更多的行動wie「onComplete」功能。如何獲得Fancybox的觸發器?

如何獲得觸發器爲jQuery-Object? $(this)接縫引用fancybox本身,沒有鏈接到原始觸發器。


解決方案:

$('a.fancybox').click(function(e){ 
    e.preventDefault(); 
    var trigger = $(this); 
    $.fancybox({ 
     'href' : this.href, 
     'onComplete' : function() { 
      if (trigger.hasClass('specific_class')) { 
       //do something 
      } else { 
       //do something else or nothing 
      } 
     } 
    }); 
}); 

回答

1

試着這麼做:

$("a").click(function(){ 
     var trigger = this; 
     $.fancybox({ 
      href : this.href, 
      onComplete : function() { 
       if ($(trigger).is(".someClass")) { 
        // ... 
       } 
      } 
     }); 
    }); 
+0

得好好的,只是添加的事情是event.preventDefault(),這樣瀏覽器將不跟隨鏈接。 謝謝! – Tim 2010-08-03 12:44:43