<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <title>Title</title> </head> <body> </body> <script> /*switch语句 * 一旦条件满足不会出来,直到遇到break语句*/ /*在case后的常量表达式不能相同 * case语句允许多个语句,不需要{} * case后必须有个break*/ var yue=parseInt(prompt("请输入月份")) switch (yue){ case 1: case 2: case 3: alert("第一季度"); case 4: case 5: case 6: alert("第二季度"); case 7: case 8: case 9: alert("第三季度"); case 10: case 11: case 12: alert("第四季度"); } /*多重if和switch都可以实现多路分支 * 多重if实现俩路三路分支方便,三路以上建议用switch * 使用switch时,注意case后的常量表达式 * if用块状判断,switch用点状判断*/ </script> </html>
js中的 switch判断用法
最新推荐文章于 2024-07-15 16:14:02 发布