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

2019-02-06 00:23发布

问题:

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

for example:

$.include('myscript.js'); 

?

回答1:

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

$.getScript('ajax/test.js', function() {
    alert('Load was performed.');
});


回答2:

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.