문제

I'm trying to load several scripts at runtime using Jquery, and then fire an event once they are loaded. The code has to handle an arbitrary number of scripts, so I use

$.when.apply

The problem is that the event is not triggered at the right time. Here is my jsfiddle:

http://jsfiddle.net/dams_666/kWP36/93/

for (var i = 0; i < myScripts.length; i++) {
    deferred.push(getScript(myScripts[i]));
}

$.when.apply($, deferred).then(finished());

Thanks in advance for your help

도움이 되었습니까?

해결책

You are invoking the finished function, instead of passing it as an argument. To pass it, use

$.when.apply($, deferred).then(finished);

Instead of

$.when.apply($, deferred).then(finished());
라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top