[removed]how to write $(document).ready like event without jquery

后端 未结 7 1776
醉梦人生
醉梦人生 2020-11-27 04:19

in jquery $(document).ready(function) or $(function) , how could I do the same thing without jquery, and I need browser compatiable, and allow to attach more than one functi

7条回答
  •  天涯浪人
    2020-11-27 04:36

    Edit

    The DomReady event does not exist nativly in javascript. You can implement your own by following some wonderful work done by people like Dean Edwards here and here with those in place you can perform a similar event attachment process on document instead of window.


    Check out user83421's answer to How do I add an additional window.onload event in Javascript

    To recap here as well.

    if (window.addEventListener) // W3C standard
    {
      window.addEventListener('load', myFunction, false); // NB **not** 'onload'
    } 
    else if (window.attachEvent) // Microsoft
    {
      window.attachEvent('onload', myFunction);
    }
    

提交回复
热议问题