我想要一个函数每隔1秒运行一次,它会遍历这四种情况。 它什么都做不了。这是代码。
var countX = 1;
setInterval(finalBattle, 1000);
function finalBattle() {
switch (countX)
case 1:
elemAttack.innerHTML = finalCut[counter];
counter++;
countX++;
break;
case 2:
elemComment.innerHTML = finalCut[counter];
counter++;
countX++;
break;
case 3:
elemDefense.innerHTML = finalCut[counter];
counter++;
countX++;
break;
case 4:
elemComment.innerHTML = finalCut[counter];
counter++;
countX = 1;
break;
}
我已经检查过,问题不在于elemAttack或finalcut数组。
答案 0 :(得分:0)
您的情况应该使用==
(相等),而不是=
(作业)。
变化:
if (countX = 2) {
要:
if (countX == 2) {
答案 1 :(得分:0)
您的开关需要将案例陈述包装在{}
所以它将是
var countX = 1;
setInterval(finalBattle, 1000);
function finalBattle() {
switch (countX) {
case 1:
elemAttack.innerHTML = finalCut[counter];
counter++;
countX++;
break;
case 2:
elemComment.innerHTML = finalCut[counter];
counter++;
countX++;
break;
case 3:
elemDefense.innerHTML = finalCut[counter];
counter++;
countX++;
break;
case 4:
elemComment.innerHTML = finalCut[counter];
counter++;
countX = 1;
break;
}
}