该脚本使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

为什么会崩溃?

最佳答案

在内部循环中:

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

您正在增加bar而不是bar2。因此,该循环将永远不会结束,因为bar2不会改变。

10-05 20:38