21 指定次數循環
1: <script>
2: <!--
3: var myArray = new Array(3);
4: myArray[0] = 「Item 0」;
5: myArray[1] = 「Item 1」;
6: myArray[2] = 「Item 2」;
7: for (i = 0; i < myArray.length; i++) {
8: document.write(myArray
+ 「<br>」); 9: } 10: // --> 11: </script> 22 設定未來執行 1: <script> 2: <!-- 3: function hello() { 4: window.alert(「Hello」); 5: } 6: window.setTimeout(「hello()」,5000); 7: // --> 8: </script> 23 定時執行函數 1: <script> 2: <!-- 3: function hello() { 4: window.alert(「Hello」); 5: window.setTimeout(「hello()」,5000); 6: } 7: window.setTimeout(「hello()」,5000); 8: // --> 9: </script> 24 取消定時執行 1: <script> 2: <!-- 3: function hello() { 4: window.alert(「Hello」); 5: } 6: var myTimeout = window.setTimeout(「hello()」,5000); 7: window.clearTimeout(myTimeout); 8: // --> 9: </script> 25 在頁面卸載時候執行函數 1: <body onUnload=」functionName();」> 2: Body of the page 3: </body> JavaScript就這麼回事2:瀏覽器輸出 26 訪問document對象 1: <script language=」JavaScript」> 2: var myURL = document.URL; 3: window.alert(myURL); 4: </script> 27 動態輸出HTML 1: <script language=」JavaScript」> 2: document.write(「<p>Here’s some information about this document:</p>」); 3: document.write(「<ul>」); 4: document.write(「<li>Referring Document: 「 + document.referrer + 「</li>」); 5: document.write(「<li>Domain: 「 + document.domain + 「</li>」); 6: document.write(「<li>URL: 「 + document.URL + 「</li>」); 7: document.write(「</ul>」); 8: </script> 28 輸出換行 1: document.writeln(「<strong>a</strong>」); 2: document.writeln(「b」); 29 輸出日期 1: <script language=」JavaScript」> 2: var thisDate = new Date(); 3: document.write(thisDate.toString()); 4: </script> 30 指定日期的時區 1: <script language=」JavaScript」> 2: var myOffset = -2; 3: var currentDate = new Date(); 4: var userOffset = currentDate.getTimezoneOffset()/60; 5: var timeZoneDifference = userOffset - myOffset; 6: currentDate.setHours(currentDate.getHours() + timeZoneDifference); 7: document.write(「The time and date in Central Europe is: 「 + currentDate.toLocaleString()); 8: </script>