How to do jquery code AFTER page loading?

前端 未结 8 1866
庸人自扰
庸人自扰 2020-12-22 19:07

If you want an event to work on your page, you should call it inside the $(document).ready() function. Everything inside it will load as soon as the D

8条回答
  •  情书的邮戳
    2020-12-22 19:32

    Use load instead of ready:

    $(document).load(function () {
     // code here
    });
    

    Update You need to use .on() since jQuery 1.8. (http://api.jquery.com/on/)

    $(window).on('load', function() {
     // code here
    });
    

    From this answer:

    According to http://blog.jquery.com/2016/06/09/jquery-3-0-final-released/:

    Removed deprecated event aliases

    .load, .unload, and .error, deprecated since jQuery 1.8, are no more. Use .on() to register listeners.

    https://github.com/jquery/jquery/issues/2286

提交回复
热议问题