1

2 つの画像の配列がありますが、2 番目の画像に対して onload が起動しません。しかし、クロムリソースでは、画像はすべて素晴らしく読み込まれています...何が原因でしょうか?

これは私のコードです:

var test = new Array();
    test[0] = new Image();
    test[0].src = 'tile1.png';  
    test[1]  = new Image();
    test[1].src = 'tile2.png';      


    test[0].onload = function(){    
        console.log('loaded 1');    

            test[1].onload = function(){
               console.log('loaded 2');
        }
    }

私は私loaded 1の中に入るだけですがconsole.log、決してloaded 2.

しかし、Chromeネットワークではtile2.png、なぜ私のonload関数が起動しないのですか??

4

1 に答える 1

3

2 番目onloadの関数は最初の関数内で宣言されているため、削除して外側に配置します。

var test = new Array();
test[0] = new Image();
test[0].src = 'tile1.png';  
test[1]  = new Image();
test[1].src = 'tile2.png';      


test[0].onload = function(){    
    console.log('loaded 1'); 
}

test[1].onload = function(){
    console.log('loaded 2');
}
于 2013-07-02T03:46:03.937 に答える