Definition and Usage
The onload event occurs immediately after a page or an image is loaded.
Syntax
| onload="JavaScriptCode" |
| Parameter | Description |
|---|---|
| JavaScriptCode | Required. Specifies a JavaScript to be executed when the event occurs |
Supported by the following HTML tags:
| <body>, <img> |
Supported by the following JavaScript objects:
| body, image |
Browser Support
The onload event is supported in all major browsers.
Examples
Example 1Alert "Page is loaded" immediately after a page is loaded:
Try it yourself » |
Example 2Alert "Image is loaded" immediately after an image is loaded:
Try it yourself » |
本文介绍了HTML中onload事件的定义及用法,包括其语法、参数说明、支持的HTML标签和JavaScript对象,以及浏览器兼容性情况。通过两个实例展示了如何在页面和图片加载完成后触发JavaScript代码执行。

719

被折叠的 条评论
为什么被折叠?



