onload





js/script.js
  • function funShow() {
  •  document.body.childNodes[5].innerHTML = '<h1>Hello World!</h1>';
  • }
  •  
  • window.onload = function() {
  •  document.body.childNodes[1].onclick = funShow;
  • }
  • function funShow() {
  •  document.body.childNodes[5].innerHTML = '<h1>Hello World!</h1>';
  • }
  •  
  • window.onload = function() {
  •  document.body.childNodes[1].onclick = funShow;
  • }


index.html
  • <!DOCTYPE html>
  • <html>
  • <head>
  •  <meta charset="utf-8" />
  •  <title>New Page</title>
  •  <script src="js/script.js"></script>
  • </head>
  • <body>
  •  <input type="button" value="OK" />
  •  <br />
  •  <div></div>
  • </body>
  • </html>
  • <!DOCTYPE html>
  • <html>
  • <head>
  •  <meta charset="utf-8" />
  •  <title>New Page</title>
  •  <script src="js/script.js"></script>
  • </head>
  • <body>
  •  <input type="button" value="OK" />
  •  <br />
  •  <div></div>
  • </body>
  • </html>