Jquery tabs - Showing a confirmation before activate

China☆狼群 提交于 2019-12-04 04:49:22

问题


I'm using jquery UI's tabs. When a user switches tabs, I'm checking for unsaved changes, and prompting the user accordingly. However, before the user even clicks Yes or No, the tab loads anyway. Does anyone know how I can get my function to NOT return anything until after the result has come back from my fancybox dialog?

You can see I've tried a couple of different methods to return my boolean value in CheckSomething().

$("#myTabs").tabs({ 
    select:
        function (event, ui) {
            return CheckSomething();
        },

    show: 
        function (event, ui) { 
            //do some stuff
        }
});

function CheckSomething() {
    var loadMyTab = true;  //If I set this to false, then it always returns false.
    if (myCondition) {
        //Show a FancyBox prompt.

        if (fancyYes) {
            //return true;
            loadMyTab= true;
        }
        else {
            //return false;
            loadMyTab = false;
        }
    }
    else {
        //return true;
        loadMyTab = true;
    }
    return loadMyTab;
}

回答1:


With a standard confirm instead of a fancy is working can it be a fast solution? http://jsfiddle.net/nuywj/




回答2:


I ended up going w/ a standard javascript confirm box instead of FancyBox. That solved my problem, because Confirm will block code from being executed:

function CheckSomething() {
    if (myCondition) {
        return confirm("Are you sure you want to change tabs without saving?");
    }
    else {
        return true;
    } 
}


来源:https://stackoverflow.com/questions/12959814/jquery-tabs-showing-a-confirmation-before-activate

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!