开发者

Loading JS dynamically from another JS (jQuery)

开发者 https://www.devze.com 2022-12-14 10:18 出处:网络
I\'d like to know if I can load an external JS dynamically based on some condition, for example: $(window).load(function () {

I'd like to know if I can load an external JS dynamically based on some condition, for example:

$(window).load(function () {
   if($.browser.msie && $.browser.version=="6.0") {
     // load ie.js
     // do stuf开发者_如何学Pythonf using ie.js
   }
});


JQuery's GetScript should do it.

$.getScript("yourscirpt.js", function() {
    alert('Load Complete');
});


If not using jquery, use this to include js

document.writeln('<script type="text/javascript" src="your.js"></script>');


Use $.getScript(url,callback); it loads the script, and executes it.

0

精彩评论

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