如何使用jQuery在delay()之后重定向?

Gui*_*sta 5 html javascript jquery

我正在使用jQuery delay()函数来延迟show()事件,但之后我想更改页面的location.href.我怎样才能做到这一点?

$('#error').delay(800).show();
location.href = '/profile'
Run Code Online (Sandbox Code Playgroud)

对不起,我忘了提及我也想延迟重定向.

Mar*_*ark 8

为show()提供回调

$('#error').delay(800).show(0, function () {
    setTimeout(function () {
        location.href = '/profile'
    }, 8000);
});
Run Code Online (Sandbox Code Playgroud)

关于.show()的文档http://api.jquery.com/show/

'show'将在800毫秒后发生,然后在显示元素后,重定向将在8秒后发生.使用此代码,您可以说有2个"延迟".