jquery: how to include other .js-files into .js

2019-02-06 00:00发布

Is there any jquery plugin (instead of incldeMany) or simple function to include js-files on demand ?

for example:

$.include('myscript.js'); 

?

2条回答
老娘就宠你
2楼-- · 2019-02-06 00:19

Not exactly a jQuery plugin, but you might try looking into RequireJS. Especially the "How to use RequireJS with jQuery" section.

I don't have much experience with this solution yet, but from what I've read and played around with I like the possibilities.

查看更多
Melony?
3楼-- · 2019-02-06 00:43

How about jQuery.getScript()? It's built in to jQuery and works like so:

$.getScript('ajax/test.js', function() {
    alert('Load was performed.');
});
查看更多
登录 后发表回答