开发者

Jquery loading dynamic libraries

I am making a script where my jquery loads a jquery plugin with the getScript() method. But for some reason the code that I load only works after my script has ended.

So the procedure:

  1. load jquery
  2. do the getScript() method and load the plugin.
  3. try to use the plugin ($('#test').myPlugin()) but crashes.
  4. script ended. try $('#test').my开发者_C百科Plugin() in chrome web developer. Works perfectly.


The getScript()-method retrieves the script asynchronous, so you have to wait till it has loaded (usually through the success()-method) to call it. I guess you're not doing that.

So try

getScript("script").success(function() {
    $('#test').myPlugin();
});
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜