How to load one JavaScript file from another?

前端 未结 5 552
情话喂你
情话喂你 2020-12-15 03:31

How do you load one JavaScript file from another JavaScript file, like CSS? In CSS we use write @import url(\"mycss.css\");.

Is there any way to do it i

5条回答
  •  轻奢々
    轻奢々 (楼主)
    2020-12-15 04:13

    Yes. If you want in pure JavaScript, you have to create dynamically a script tag, and append it to the document.

    Yes. If you use the jQuery library, you can use the $.getScript method.

    $.getScript("another_script.js");
    

提交回复
热议问题