且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

使用jQuery加载脚本

更新时间:2023-12-04 23:29:16

您需要使用getScript加入脚本,而不是阿贾克斯。 Ajax是用于装载数据,而不是执行code。

You need to use getScript, not ajax. Ajax is for loading data, not for executing code.

如果你需要加载多个文件,尝试这样的事:

If you need to load multiple files, try something like this:

var scripts = ['plugin.js', 'test.js'];
for(var i = 0; i < scripts.length; i++) {
  $.getScript(scripts[i], function() {
    alert('script loaded');
  });
}