[removed] vs <body onload=“”/>

后端 未结 13 2097
盖世英雄少女心
盖世英雄少女心 2020-11-22 13:45

What exactly is the difference between the window.onload event and the onload event of the body tag? when do I use which and how shoul

13条回答
  •  南方客
    南方客 (楼主)
    2020-11-22 14:36

    They both work the same. However, note that if both are defined, only one of them will be invoked. I generally avoid using either of them directly. Instead, you can attach an event handler to the load event. This way you can incorporate more easily other JS packages which might also need to attach a callback to the onload event.

    Any JS framework will have cross-browser methods for event handlers.

提交回复
热议问题