jQuery $(document).ready () fires twice

前端 未结 13 900
忘了有多久
忘了有多久 2020-11-29 03:13

I\'ve been sifting around the web trying to find out whats going on here and I have not been able to get a concrete answer.

I have one $(document).ready

13条回答
  •  情话喂你
    2020-11-29 03:44

    This happened to me when using KendoUI... invoking a popup window would cause the document.ready event to fire multiple times. The easy solution is to set a global flag so that it only runs once:

    var pageInitialized = false;
    $(function()
    {
        if(pageInitialized) return;
        pageInitialized = true;
        // Put your init logic here.
    });
    

    It's sort of hack-ish, but it works.

提交回复
热议问题