有没有做旅游攻略的网站,自己做网站语言包怎么做,注册网站给谁交钱,建什么网站收益比较号从JavaScript 1.2开始#xff0c;您可以使用 switch 语句来处理这种情况#xff0c;它比重复的 if ... else if 语句更有效。
流程图
以下流程图说明了switch-case语句的工作原理。 switch 语句的目的是给出一个要求值的表达式#xff0c;并根据表达式的值执行多个不同的语…
从JavaScript 1.2开始您可以使用 switch 语句来处理这种情况它比重复的 if ... else if 语句更有效。
流程图
以下流程图说明了switch-case语句的工作原理。 switch 语句的目的是给出一个要求值的表达式并根据表达式的值执行多个不同的语句。解释器会根据表达式的值检查每个 case 条件 直到找到匹配项如果没有匹配项将使用默认(default)条件。
switch (expression) {case condition 1: statement(s)break;case condition 2: statement(s)break;...case condition n: statement(s)break;default: statement(s)
} break 语句指示特定案例的结束如果省略它们则在以下每种情况下解释器将继续执行每个语句。
请尝试以下示例来实现switch-case语句。
htmlbody script type text/javascript!--var grade A;document.write(Entering switch blockbr /);switch (grade) {case A: document.write(Good jobbr /);break;case B: document.write(Pretty goodbr /);break;case C: document.write(Passedbr /);break;case D: document.write(Not so goodbr /);break;case F: document.write(Failedbr /);break;default: document.write(Unknown gradebr /)}document.write(Exiting switch block);//--/script pSet the variable to different value and then try.../p/body
/html
运行上面代码输出
Entering switch block
Good job
Exiting switch block
Set the variable to different value and then try...
break语句在switch-case语句中起主要作用请尝试以下使用switch-case语句而不使用任何break语句的代码。
htmlbody script type text/javascript!--var grade A;document.write(Entering switch blockbr /);switch (grade) {case A: document.write(Good jobbr /);case B: document.write(Pretty goodbr /);case C: document.write(Passedbr /);case D: document.write(Not so goodbr /);case F: document.write(Failedbr /);default: document.write(Unknown gradebr /)}document.write(Exiting switch block);//--/script pSet the variable to different value and then try.../p/body
/html
运行上面代码输出
Entering switch block
Good job
Pretty good
Passed
Not so good
Failed
Unknown grade
Exiting switch block
Set the variable to different value and then try... 参考链接
https://www.learnfk.com/javascript/javascript-switch-case.html