我有来自 W3School 的确切代码。虽然代码可以在他们的网站上运行,但它在我的 PC 上并不能真正运行(单击按钮不会产生任何结果)。我认为 Date() 对象的 getDay() 方法不能正常工作,但我仍然无法弄清楚确切的问题是什么。先感谢您。
来自 W3School 的原始链接: http ://www.w3schools.com/js/tryit.asp?filename=tryjs_switch
<!DOCTYPE html>
<html>
<body>
<p>Click the button to display what day it is today.</p>
<button onclick="myFunction()">Try it</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>
</body>
</html>