How to run/load a separate javascript file selectively from inside javascript?

前端 未结 4 394
生来不讨喜
生来不讨喜 2021-01-24 16:01

I have 3 JavaScript files that I would like to load from an index.html file. I\'m choosing among them by using if statements which I only know how to d

4条回答
  •  囚心锁ツ
    2021-01-24 16:33

    var s = document.createElement("script");
    s.src="myscript.js";
    document.head.appendChild(s);
    

    Oh man, so many same answers at the same time.

提交回复
热议问题