<!doctype html>
<html>
<head>
<meta charset="utf-8">
<title>javascript switch语句</title>
</head>
<body>
<p>点击下面的按钮来显示今天是周几:</p>
<button onclick="myfunction()">点击这里</button>
<p id="demo"></p>
<script>
function myfunction() {
var x;
var d = new date().getday();
switch (d) {
case 0:
x = "today it's sunday";
break;
case 1:
x = "today it's monday";
break;
case 2:
x = "today it's tuesday";
break;
case 3:
x = "today it's wednesday";
break;
case 4:
x = "today it's thursday";
break;
case 5:
x = "today it's friday";
break;
case 6:
x = "today it's saturday";
break;
}
document.getelementbyid("demo").innerhtml = x;
}
</script>
<p>点击下面的按钮,会显示出基于今日日期的消息</p>
<button onclick="myfunction()">点击这里</button>
<p id="demo"></p>
<script>
function myfunction() {
var x;
var d = new date().getday();
switch (d) {
case 6:
x = "today is saturday";
break;
case 0:
x = "today is sunday";
break;
default:
x = "looking forward to the weekend";
}
document.getelementbyid("demo").innerhtml = x;
}
</script>
</body>
</html>