代码崩溃Firefox

时间:2015-10-14 16:14:25

标签: javascript html firefox crash

此脚本崩溃了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

为什么会崩溃?

1 个答案:

答案 0 :(得分:4)

在内循环中:

            for (var bar2 = 0; bar2 < blueSelectorBar.length; bar++){
                blueSelectorBar[bar2].style.border = "3px solid black"
            };

您正在递增bar而不是bar2。因此,该循环永远不会完成,因为bar2永远不会改变。