After all $(document).ready() have run, is there an event for that?

后端 未结 6 1270
眼角桃花
眼角桃花 2020-12-04 19:15

I have a first.js file included in the page index.php that have something like this:

$(function(){

    $(\"#my_slider\").slider(\"value\", 10);

});
         


        
6条回答
  •  粉色の甜心
    2020-12-04 19:30

    One of the goals of jQuery's $(document).ready() function is that the standard javascript window.onload event won't run until everything on the page is loaded (including images, etc.), even though functions can usefully start running well before that. So $(document).ready() runs as soon as the DOM hierarchy is constructed.

    Given this, one option would be to run your "after everything else" script on page load. This won't guarantee that all of the $(document).ready() scripts have completed, though.

    A better but more complicated option is to create a function that checks for the existence of the sliders, and if they don't exist, calls "setTimeout" on itself, so it can wait a few milliseconds and try again.

    (To answer your specific question, no, there is no "after all $(document).ready() have run" callback.)

提交回复
热议问题