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

2018-12-31 15:27发布

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 should it be done correctly?

标签: javascript
13条回答
梦醉为红颜
2楼-- · 2018-12-31 16:19

If you're trying to write unobtrusive JS code (and you should be), then you shouldn't use <body onload="">.

It is my understanding that different browsers handle these two slightly differently but they operate similarly. In most browsers, if you define both, one will be ignored.

查看更多
登录 后发表回答