1 <!DOCTYPE html> 2 <html> 3 <head lang="en"> 4 <meta charset="UTF-8"> 5 <title></title> 6 </head> 7 <body> 8 <script> 9 function showFood(){ 10 var date=Number(prompt("今天星期几")); 11 switch(date){ 12 case 1: 13 console.log("今天炖牛肉"); 14 break; 15 case 2: 16 console.log("今天土豆炖牛肉"); 17 break; 18 case 3: 19 console.log("今天牛肉炖柿子"); 20 break; 21 case 4: 22 console.log("今天牛肉炖萝卜"); 23 break; 24 case 5: 25 console.log("今天香菇炖小鸡"); 26 break; 27 case 6: 28 console.log("今天星期六放假"); 29 break; 30 case 7: 31 console.log("今天星期天放假"); 32 break; 33 default: 34 console.log("您的输入有误"); 35 break; 36 } 37 } 38 </script> 39 <button onclick="showFood()">今天优惠套餐</button> 40 </body> 41 </html>
swirch-case的结束机制
1、碰到break结束
2、整个执行完毕结束
时间: 2024-10-28 03:56:14