嵌套函数调用

时间:2010-10-05 06:20:39

标签: jquery

我希望通知仅在unblock事件之后发生,但两者一起发生。我是JQuery的新手。

function isSuccess()
            {
                $(function () {
                  setTimeout('unblock()',1000);
                  $.notifyBar({
                    html: "Thank you, your settings were updated!",
                    delay: 2000,
                    animationSpeed: "normal"
                  });

                });

            }

4 个答案:

答案 0 :(得分:3)

$(function () {
    setTimeout(function() {
        unblock();
        $.notifyBar({
            html: "Thank you, your settings were updated!",
            delay: 2000,
            animationSpeed: "normal"
        });
    }, 1000);
});

答案 1 :(得分:2)

如果您希望在notifyBar之后执行unblock,请将其放在unblock

之后
setTimeout(function() {
    unblock();
    $.notifyBar({
        ...
    });
},1000);

答案 2 :(得分:1)

包装另一个匿名函数

function isSuccess()
{
    $(function () {
        function unblockAndNotify() {
            unblock();
            $.notifyBar({
                html: "Thank you, your settings were updated!",
                delay: 2000,
                animationSpeed: "normal"
            });
        }
        setTimeout(unblockAndNotify,1000);
    });
}
编辑:我打算做Darin所做的事情,并使用setTimeout声明函数内联,但不想一次引入太多新概念。

答案 3 :(得分:1)

您需要重新安排来电顺序 您必须从$.notifyBar()内拨打unblock(),或者您正在执行类似

的操作
setTimeout(function(){
   unblock();
   $.notifyBar({
          html: "Thank you, your settings were updated!",
          delay: 2000,
          animationSpeed: "normal"
   });
}, 1000);
相关问题