HTML
setTimeout() 指定延遲時間執行一段程式 setTimeout (要執行的代碼, 等待的毫秒數) or setTimeout (JavaScript 函數, 等待的毫秒數) 指定一段程式碼或函式在多少毫秒(ms)後執行,並回傳此定時器的編號。 clearTimeout() 清除定時器 可以通過將定時時產生的 ID 標識傳遞給 。 延遲時間執行 var meter = setTimeout( function , 1000)。 清除定時器 clearTimeout(meter )。
JavaScript For Loop for (初始表達式 ; 條件式 ; 遞增表達式 ) { 陳述式 代碼塊 } Example : for (var i = 0; i < 5; i++) { text += i } // 01234
JavaScript do...while Loop do { code block to be executed 陳述式 代碼塊 } while (condition 條件式); Example : <script> var text = ""; var i = 0; do { text += i + " "; i++;} while (i < 5); document.write( text ) </script>
JavaScript while Loop while ( 條件式 ) { 陳述式 代碼塊 遞增表達式} Example : <script> var text = ""; var i = 0; while (i < 5) { text += i + " "; i++;} document.write( text ) </script>
JavaScript if, else, and else if if (condition 狀況) { block of code to be executed if the condition is true 條件為真時執行的代碼塊 } else if (condition2 狀況) { block of code to be executed if the condition1 is false and condition2 is true 條件 1 為假且條件 2 為真時執行的代碼塊 } else { block of code to be executed if the condition is false 條件為假時執行的代碼塊 } 比較運算子: 等於: == 不等於:!== 大於: > 小於:< 大於等於: >= 小於等於:<= 連接兩個以上的條件都是true && 連接兩個其中一個條件成true ||
script if 條件敘述 <input onclick="Fif(this.value)" type="button" value="10" /> <input onclick="Fif(this.value)" type="button" value="30" /> <input onclick="Fif(this.value)" type="button" value="60" /> <input onclick="Fif(this.value)" type="button" value="90" /> <input onclick="Fif(this.value)" type="button" value=" " /> <span id="txt">??</span> <script> var Select = "??" ; if(x==10){ Select = "ten"} if(x==30){ Select = "thirty"} if(x==60){ Select = "sixty"} if(x==90){ Select = "ninety"} txt.innerHTML =Select ; } </script> ??
script if 條件敘述 <input onclick="Fif(this.value)" type="button" value="10" /> <input onclick="Fif(this.value)" type="button" value="30" /> <input onclick="Fif(this.value)" type="button" value="60" /> <input onclick="Fif(this.value)" type="button" value="90" /> <input onclick="Fif(this.value)" type="button" value=" " /> <span id="txt">??</span> <script> function Fif(x) { var Select = (x==10)?"is 10" : (x==30)?"is 30" : (x==60)?"is 60": (x>10)?"is 90": "??"; txt.innerHTML = Select ; } </script> ??
script if 條件敘述 請選擇 30 Please select 30 <input onclick="Fif(this.value)" type="button" value="10" /> <input onclick="Fif(this.value)" type="button" value="30" /> <input onclick="Fif(this.value)" type="button" value="60" /> <input onclick="Fif(this.value)" type="button" value="90" /> <input onclick="Fif(this.value)" type="button" value=" " /> <span id="txt">??</span> <script> function Fif(x) { if (x==30){txt.innerHTML= '選擇正確choose correctly';return } else if( x < 30) {txt.innerHTML='選擇小於/ hoose less than 30'} else {txt.innerHTML='選擇大於/ elect greater than 30' } } </script> 請選擇 30 Please select 30 ??