W3School TIY Editor
W3School 在线教程
改变方向
暗黑模式
运行代码
<!DOCTYPE html> <html> <body> <p>单击该按钮可显示今天是星期几。</p> <button onclick="myFunction()">试一试</button> <p id="demo"></p> <script> function myFunction() { var d = new Date(); var weekday = new Array(7); weekday[0] = "Sunday"; weekday[1] = "Monday"; weekday[2] = "Tuesday"; weekday[3] = "Wednesday"; weekday[4] = "Thursday"; weekday[5] = "Friday"; weekday[6] = "Saturday"; var n = weekday[d.getDay()]; document.getElementById("demo").innerHTML = n; } </script> </body> </html>