Dynamically loading Javascript files and load completion events

前端 未结 3 975
攒了一身酷
攒了一身酷 2021-01-19 07:32

today I\'ve been working on loading dynamic javascript code (files). The solution I use is :

function loadScript(scriptUrl) {
        var head = document.get         


        
3条回答
  •  星月不相逢
    2021-01-19 07:38

    You can use jquery's getScript and pass a callback function.

    $.getScript("test.js", function(){
       alert("Script loaded and executed.");
     });
    

    See: jquery.

提交回复
热议问题