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 事件屬性如何工作。

更新於: 27-9 月 -2019

203 人瀏覽

開啟你的 事業

完成課程獲得認證

開始
廣告