开发者

Jquery loading dynamic libraries

开发者 https://www.devze.com 2023-03-27 02:37 出处:网络
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.

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

精彩评论

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

关注公众号