窗口关闭后无法再次打开-取消绑定

Window won't open again after closing - unbind

本文关键字:取消 绑定 窗口      更新时间:2023-09-26

我有一个按钮打开一个弹出窗口。通过再次点击自己,弹出窗口应该关闭(这一个工作)。但是关闭后,就不可能重新打开窗口了。如何解决此解绑定问题?

//loading Popup
//0 means disabled; 1 means enabled;
var popupStatus = 0;
function loadPopup ($elem) {
    //loads popup only if it is disabled
    if(popupStatus==0){  
        $elem.fadeIn(300, function(){
        //Closing popup by clicking the button
            $("#popup-button").bind("click", function(){
                    disablePopup();
            });
        });
        popupStatus = 1;  
    }
}
//disable popup
function disablePopup(){
        //disables popup only if it is enabled  
        if(popupStatus==1){  
            $(".popup-background").fadeOut("slow");  
                    $("#popup-wrapper").fadeOut("slow");
            $("#popup-button").unbind("click", function(){
                    disablePopup();
            });
             popupStatus = 0;  
        }
    }  

在我看来没有解绑定的必要,试试这样做:

$('#popup-button').click(function(){
    $('#popup-window').fadeToggle();
});