HTML onload 事件属性
HTML onload 事件属性在 HTML 文档中加载对象时触发。
语法
语法如下 -
<tagname onload=”script”></tagname>
让我们看一个 HTML onload 事件属性的示例。
示例
<!DOCTYPE html>
<html>
<head>
<style>
body {
color: #000;
height: 100vh;
background-color: #FBAB7E;
background-image: linear-gradient(62deg, #FBAB7E 0%, #F7CE68 100%);
text-align: center;
padding: 20px;
}
</style>
<script>
function get() {
alert("Hi! you just refresh the document.");
}
</script>
</head>
<body onload="get()">
<h1>HTML onload Event Attribute Demo</h1>
<p style="color:#db133a;">Now try to refresh this document.</p>
</body>
</html>输出

现在尝试重新加载文档,以观察 onload 事件属性如何工作。

广告
数据结构
网络
RDBMS
操作系统
Java
iOS
HTML
CSS
安卓
Python
C 编程
C++
C#
MongoDB
MySQL
Javascript
PHP