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

后端 未结 7 1786
醉梦人生
醉梦人生 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

    This is all you need if you're supporting IE9+ and modern (2013) versions of Chrome, FF, Safari, etc.

    function ready(event) {
        // your code here
        console.log('The DOM is ready.', event);
        // clean up event binding
        window.removeEventListener('DOMContentLoaded', ready);
    }
    
    // bind to the load event
    window.addEventListener('DOMContentLoaded', ready);
    

提交回复
热议问题