Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/427.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 为什么setTimeout()在Firefox中的行为不同_Javascript - Fatal编程技术网

Javascript 为什么setTimeout()在Firefox中的行为不同

Javascript 为什么setTimeout()在Firefox中的行为不同,javascript,Javascript,我的脚本循环通过2014年世界杯的动态组和队数组,setTimeout用于延迟,以便一次显示一个组。此外,每组中有一个团队使用延迟显示。它在chrome和safari中工作得非常完美,但在Firefox的crack中却像它一样跳跃。此外,如果你觉得你可以使我的代码更优雅有它。我是个新手。如果您愿意,请尝试以下代码: function showTeams() { var teams = [ ['Brazil', 'Croatia', 'Cameroon', 'Mexico'], [

我的脚本循环通过2014年世界杯的动态组和队数组,setTimeout用于延迟,以便一次显示一个组。此外,每组中有一个团队使用延迟显示。它在chrome和safari中工作得非常完美,但在Firefox的crack中却像它一样跳跃。此外,如果你觉得你可以使我的代码更优雅有它。我是个新手。如果您愿意,请尝试以下代码:

function showTeams() {
var teams = [
    ['Brazil', 'Croatia', 'Cameroon', 'Mexico'],
    ['Australia', 'Chile', 'Holland', 'Spain', ''],
    ['Colombia', 'Cote D\'Ivoire', 'Greece', 'Japan'],
    ['Costa Rica', 'England', 'Italy', 'Uruguay'],
    ['Ecuador', 'France', 'Honduras', 'Switzerland'],
    ['Argentina', 'Bosnia', 'Iran', 'Nigeria'],
    ['Germany', 'Ghana', 'Portugal', 'USA'],
    ['Algeria', 'Belgium', 'Korea', 'Russia']
];
//loop through each array and list teams 
var c = 0;

function groupLoop() {
    setTimeout(function () {
        count = c;
        var nation = teams[c];
        teamLoop(nation, count);
        if (c < 7) {
            groupLoop();
        };
        c++
    }, 2500);
}; //end groupLoop
function teamLoop(nation, count) {
    function riteAll() {
        var group = ['Group A', 'Group B', 'Group C', 'Group D', 'Group E',
            'Group F', 'Group   G', 'Group H'
        ];
        var squads = document.getElementById("squads");
        var li = document.createElement('li');
        var h2 = document.createElement('h2');
        h2.id = "listHead";
        var list = squads.appendChild(document.createElement('ul'));
        var mygroup = list.appendChild(h2);
        mygroup.appendChild(document.createTextNode(group[count]));
        j = 0;

        function listLoop() {
            setTimeout(function () {
                item = list.appendChild(li.cloneNode());
                item.appendChild(document.createTextNode(nation[j]));
                j++;
                if (j < 4) {
                    listLoop();
                };
            }, 300);
        } //end listLoop;
        listLoop();
    } //endRiteAll 
    riteAll();
}; /*END teamLoop, End timeout*/ ;
groupLoop();
函数showTeams(){
风险值团队=[
[“巴西”、“克罗地亚”、“喀麦隆”、“墨西哥”],
[‘澳大利亚’、‘智利’、‘荷兰’、‘西班牙’、“”],
[“哥伦比亚”、“科特迪瓦”、“希腊”、“日本”],
[“哥斯达黎加”、“英格兰”、“意大利”、“乌拉圭”],
[“厄瓜多尔”、“法国”、“洪都拉斯”、“瑞士”],
[“阿根廷”、“波斯尼亚”、“伊朗”、“尼日利亚”],
[“德国”、“加纳”、“葡萄牙”、“美国”],
[‘阿尔及利亚’、‘比利时’、‘韩国’、‘俄罗斯’]
];
//循环遍历每个阵列并列出团队
var c=0;
函数groupLoop(){
setTimeout(函数(){
计数=c;
var nation=团队[c];
teamLoop(国家、计数);
if(c<7){
groupLoop();
};
C++
}, 2500);
};//结束分组循环
功能团队循环(国家、计数){
函数(全部){
var group=['A组'、'B组'、'C组'、'D组'、'E组',
“F组”、“G组”、“H组”
];
var squads=document.getElementById(“squads”);
var li=document.createElement('li');
var h2=document.createElement('h2');
h2.id=“列表头”;
var list=squads.appendChild(document.createElement('ul');
var mygroup=list.appendChild(h2);
mygroup.appendChild(document.createTextNode(组[count]);
j=0;
函数listLoop(){
setTimeout(函数(){
item=list.appendChild(li.cloneNode());
item.appendChild(document.createTextNode(国家[j]);
j++;
if(j<4){
listLoop();
};
}, 300);
}//结束listLoop;
listLoop();
}//endRiteAll
riteAll();
};/*结束团队循环,结束超时*/;
groupLoop();

})

您的
j
变量是全局变量。我不认为这是问题的原因,但你可能不想要它。对我来说,在Firefox29上它工作得很好。您正在测试哪个版本的Firefox?另外:函数声明后不需要分号。我真的不知道为什么“它像裂纹一样跳跃”,但我会把团队安排得有点不同:
var-goups=[{name:'groupa',teams:['Brazil','croade']},{name:'groupb',teams:['Australia','Chile']}
。只是为了让一切都在一起。谢谢大家的意见。我在Firefox27上。Mozilla网站说29甚至还没有发布,你已经领先了。Marcel感谢您的建议,我需要继续处理我的数组,不知道语法是一个选项。