开发者

How can I fire something after $(document).ready() completes?

Is there a way to have your function be called as the LAST in the $(document).ready() queue or, is there a way to trigger an event once this has completed?

I want to essentially see if something was fired by $(document).ready() and, if not, fire it after wards. If I put this code into document ready then there is no guarantee it will execute last so开发者_JS百科 could result in multiple checks.


You can set a global variable when your function is fired, and check that before running it again:

E.g.,

function myFunc()
{
    if (myFuncHasFired)
        return;
    myFuncHasFired = true;
    //your func code here
}

This does not guarantee your function will run last, but satisfies what I think is your real requirement that the function not run multiple times in one request.


Add another $(document).ready() block to the end of your code. jQuery executes them in the order it sees them, so if you put another block at the end of the code, it should be called after the other finishes.


This sounds like the perfect use case for the readyX plugin: http://plugins.jquery.com/project/readyx

The plugin provides a queue for ready events that should happen last.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜