2013-06-03 83 views
0

我有一個網址的數組。我喜歡加載它們中的每一個,並將內容附加到元素。JQuery加載多個網址,並返回一個延遲結束

var myStrArray = ["http://www.google.de", "http://www.facebook.de", "http://www.lycos.de"]; 

//Initialize local deferred for myStrArray 
var myDeferredArray = []; 
for (var i = 0; i < myStrArray; i++) 
{ 
    myDeferredArray[i] = $.Deferred(); 
} 

for (var i = 0; i < myStrArray.length; i++) 
{ 
    $(element).load(myStrArray, function() { 
     doSomething(); 
     myDeferredArray[i].resolve(); 
    }); 
} 

return myDeferredArray as single deferred 

回答

0

得到一個遞延

$.when.apply(null, deferreds);