addEventListenerを使ったイベント処理の記述。
loadはサイトが読み込まれたときのイベント。
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 | <!DOCTYPE html> <html> <head> <meta charset= "utf-8" > <title>起動時のイベント</title> <script> window.addEventListener( "load" , function (){ console.log( "起動したよ!" ); document.getElementById( "message" ).innerHTML = "起動時のイベントで書き換えました" ; }); </script> </head> <body> <h1>起動時のイベント</h1> <p id= "message" >onloadイベントをテストしています。</p> </body> </html> |
コメント