gpt4 book ai didi

javascript - 输出不显示javascript

转载 作者:行者123 更新时间:2023-11-28 11:53:21 25 4
gpt4 key购买 nike

使用javascript,由于某种原因,即使 d.getDay() 是 2,我也无法通过该函数输出“星期二”。

<!DOCTYPE html>
<html>
<body>

<p>The getDay() method returns the weekday as a number:</p>

<p id="demo"></p>

<script>
function getDayOfWeek(day){
if (day == 1){
return "Monday";
else if (day == 2){
return "Tuesday";
else{
return "Otherday";
}
}

var d = new Date();
document.getElementById("demo").innerHTML = getDayOfWeek(d.getDay());
</script>

</body>
</html>

最佳答案

看起来您缺少 else 语句中的右大括号。我在下面更新了您的代码片段。

function getDayOfWeek(day){
if (day == 1) {
return "Monday";
} else if (day == 2) {
return "Tuesday";
} else {
return "Otherday";
}
}

var d = new Date();
document.getElementById("demo").innerHTML = getDayOfWeek(d.getDay());

关于javascript - 输出不显示javascript,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31255265/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com