亚洲国产日韩欧美一区二区三区,精品亚洲国产成人av在线,国产99视频精品免视看7,99国产精品久久久久久久成人热,欧美日韩亚洲国产综合乱

JavaScript switch statement

JavaScript switch statement

The switch statement is used to perform different actions based on different conditions.

JavaScript switch statement

Use the switch statement to select one of multiple blocks of code to execute.

Syntax

switch(n)
{
case 1:
Execute code block 1
break;
case 2:
Execute code Block 2
break;
default:
n Code that is not executed simultaneously with case 1 and case 2
}

Working principle: First set the expression n (usually a variable ). The value of the expression is then compared to the value of each case in the structure. If there is a match, the code block associated with the case is executed. Please use break to prevent the code from automatically running to the next case.

點(diǎn)擊下面的按鈕來(lái)顯示今天是周幾:點(diǎn)擊這里function myFunction(){
var x;
var d=new Date().getDay();
switch (d){
  case 0:x="今天是星期日";
    break;
 case 1:x="今天是星期一";
        break;
  case 2:x="今天是星期二";
        break;
        case 3:x="今天是星期三";
    break;
  case 4:x="今天是星期四";
    break;
  case 5:x="今天是星期五";
        break;
  case 6:x="今天是星期六";
    break;
 }
document.getElementById("demo").innerHTML=x;
}
Continuing Learning
||
<!DOCTYPE html> <html> <head> <meta charset="utf-8"> </head> <body> <p>點(diǎn)擊下面的按鈕來(lái)顯示今天是周幾:</p> <button onclick="myFunction()">點(diǎn)擊這里</button> <p id="demo"></p> <script> function myFunction(){ var x; var d=new Date().getDay(); switch (d){ case 0:x="今天是星期日"; break; case 1:x="今天是星期一"; break; case 2:x="今天是星期二"; break; case 3:x="今天是星期三"; break; case 4:x="今天是星期四"; break; case 5:x="今天是星期五"; break; case 6:x="今天是星期六"; break; } document.getElementById("demo").innerHTML=x; } </script> </body> </html>
submitReset Code