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