有些時間咱們但願能按需動態加載js文件,而不是直接在HTML中寫script標籤。async
如下爲示例代碼:spa
1 var js = document.createElement('script'); 2 js.async = true; 3 js.src = jsSrc; 4 js.onload = function() { 5 // 加載完成了 6 }