JavaScript載入事件(onload)

載入事件(onload)


事件會在頁面載入完成後,立即發生,同時執行被呼叫的程式。
注意:

  • 載入頁面時,觸發onload事件,事件寫在<body>標籤內。

  • 此節的載入頁面,可理解為開啟一個新頁面時。
    如下程式碼,當載入一個新頁面時,彈出對話框「載入中......」。

<!DOCTYPE HTML>
<html>
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
        <title>php.cn</title>
        <script>
            function fun(){
                window.alert("加载中......")
            }
        </script>
    </head>
    <body onload="fun()">
        欢迎来到php.cn
    </body>
</html>


繼續學習
||
<!DOCTYPE HTML> <html> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8"> <title>php.cn</title> <script> function fun(){ window.alert("加载中???") } </script> </head> <body onload="fun()"> 欢迎来到php.cn </body> </html>
關於我們 免責聲明 Sitemap
PHP中文網:公益線上PHP培訓,幫助PHP學習者快速成長!