演示代码:
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title></title>
<script type="text/javascript">
// 8号:食品8折
// 18号:服装8折
// 28号:电器8折
// var a = prompt("请输入日期");
// if (a == 8) {
// document.write("食品8折");
// } else if (a == 18 ) {
// document.write("服装8折");
// } else if (a == 28) {
// document.write("电器8折");
// } else {
// document.write("没有打折");
// }
var a = prompt("请输入日期");
a = a*1;
switch (a){ // a是要判断的对象
case 8: // case是我们要判断对象的值
document.write("食品8折");
break; // 条件成立结束判断,跳出switch
case 18:
document.write("服装8折");
break;
case 28:
document.write("电器8折");
break;
default: // 条件都不成立时
document.write("没有打折");
break;
}
</script>
</head>
<body>
</body>
</html>