Body onload event
Definition and Usage
onload event fires immediately after the page is loaded.
grammar
onload="JavaScriptCode"
参数 | 描述 |
---|---|
JavaScriptCode | 必需。规定该事件发生时执行的 JavaScript。 |
Browser Support
All major browsers support onload event
Examples
Examples
In this example, the text "Page is loaded" will be displayed in the status bar:
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>本教程(w3big.com)</title>
<script>
function myFunction(){
alert("页面加载完成");
}
</script>
</head>
<body onload="myFunction()">
<h1>Hello World!</h1>
</body>
</html>
<html>
<head>
<meta charset="utf-8">
<title>本教程(w3big.com)</title>
<script>
function myFunction(){
alert("页面加载完成");
}
</script>
</head>
<body onload="myFunction()">
<h1>Hello World!</h1>
</body>
</html>
try it"
Body Object