gpt4 book ai didi

javascript - 根据 currentTime 更改类属性

转载 作者:行者123 更新时间:2023-11-28 13:50:08 27 4
gpt4 key购买 nike

所以,我有一些代码由于某些奇怪的原因而不起作用。它的任务是,更改 id 为 blogtxt 的元素的属性 class IF day 变量等于 4、5 或 6(周五、周六、周日)我还希望在 day = 4 && 时使用 hours 变量。另外,我确定问题不在 IF 语句中,因为代码甚至不会执行 alert(currentTime)

Q: What is the problem with the code above?

<script>
var currentTime = new Date()
var day = currentTime.getDay()
var hours = currentTime.getHours()
alert(currentTime)
if (day = 4 && || day = 5 || day = 6) {
document.getElementById("blogtxt").setAttribute("class", "friss");
else document.getElementById("blogtxt").setAttribute("class", "");
}
</script>

最佳答案

JSLint 检测到您有一堆错误:

day = 4 应为day == 4。if 子句中有一个无关的 &&。then 子句没有右大括号,else 子句没有左大括号。

已更正代码 http://jsfiddle.net/barmar/7nRXG/

关于javascript - 根据 currentTime 更改类属性,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11448832/

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