此脚本崩溃了firefox,并在blueSelectorBar[mobIndex].style.border = "3px solid white"
以下是脚本部分
var blueSelectorBar = document.getElementById('blueSelector').getElementsByTagName('div');
for (var bar = 0; bar < blueSelectorBar.length; bar++){
var blueCurrentBox = blueSelectorBar[bar];
console.log(blueCurrentBox.dataset.mob)
var blueMobId = blueCurrentBox.dataset.mob
if (eval(blueMobId) == toReturn){
var mobIndex = bar
for (var bar2 = 0; bar2 < blueSelectorBar.length; bar++){
blueSelectorBar[bar2].style.border = "3px solid black"
};
};
};
blueSelectorBar[mobIndex].style.border = "3px solid white"
return toReturn
为什么会崩溃?
答案 0 :(得分:4)
在内循环中:
for (var bar2 = 0; bar2 < blueSelectorBar.length; bar++){
blueSelectorBar[bar2].style.border = "3px solid black"
};
您正在递增bar
而不是bar2
。因此,该循环永远不会完成,因为bar2
永远不会改变。