2011-11-03 30 views
1

有沒有方法從$ .fancybox.close()函數傳遞參數並在OnClosed事件中讀取該參數?在fancybox關閉函數中傳遞參數

是這樣的:

$("#id_div").fancybox({ 
     'width': '40%', 
     'height': '40%', 
     'autoScale': false, 
     'transitionIn': 'none', 
     'transitionOut': 'none', 
     'type': 'iframe', 
     'onClosed': function (parameter) { 
     alert(parameter);} 
    }); 

$.fancybox.close("parameter") 

回答

1

沒有,但你可以實現與變量同樣的事情。

如果你包裏面$(document).ready()你的代碼,那麼這樣的事情應該工作:

$(function(){ 
    var closedParam; 

    $("#id_div").fancybox({ 
     'width': '40%', 
     'height': '40%', 
     'autoScale': false, 
     'transitionIn': 'none', 
     'transitionOut': 'none', 
     'type': 'iframe', 
     'onClosed': function (currentArray, currentIndex, currentOpts) { 
      // Use closedParam here 
     } 
    }); 

    // In some other function 
    closedParam = ... ; 
    $.fancybox.close(); 
}); 
+0

我沒有在同一範圍內的函數(.close()和fancybox()),我不想創建一個全局變量。 – Sampat

+0

然後不,沒有辦法修改fancybox插件代碼。 – rossipedia

0

如果你不想使用全局變量使用隱藏或不DOM對象的屬性。