大家好! 我的代码一直有问题。我想我知道出了什么问题,但无论我如何努力,我似乎都无法修复它,所以我决定向社区提出这个问题。我认为这是因为第二个 if 语句与前面的语句相矛盾。来,看一下。
if (Character.style.backgroundImage === "url(../images/animations/moveRightAnimation/1.png)") {
Character.style.backgroundImage = "url(../images/animations/moveRightAnimation/2.png)";
} else (Character.style.backgroundImage != "url(../images/animations/moveRightAnimation/1.png)") {
Character.style.backgroundImage = "url(../images/animations/moveRightAnimation/1.png)";
希望您能明白我在说什么并知道答案是什么。正如我在上一篇文章中所说,我不是一个出色的程序员,所以不要过分评判我,XD。
最佳答案
没有理由重复用 else
否定的条件检查,只有 else if
才需要。改变
} else (Character.style.backgroundImage != "url(../images/animations/moveRightAnimation/1.png)") {
Character.style.backgroundImage = "url(../images/animations/moveRightAnimation/1.png)";
}
类似于
} else {
Character.style.backgroundImage =
"url(../images/animations/moveRightAnimation/1.png)";
}
关于JavaScript if else 问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46386225/