动态引入cdn js文件,并使用js中的变量常量,亲测有效
原文链接:https://blog.csdn.net/Jie_1997/article/details/112011603
function dynamicLoadJs(url, callback) {
var head = document.getElementsByTagName('head')[0];
var script = document.createElement('script');
script.type = 'text/javascript';
script.src = url;
if (typeof (callback) == 'function') {
script.onload = script.onreadystatechange = function () {
if (!this.readyState || this.readyState === "loaded" || this.readyState === "complete") {
callback();
script.onload = script.onreadystatechange = null;
}
};
}
head.appendChild(script);
}
//引入的js文件地址
let url='https://cdn.bootcdn.net/ajax/libs/jquery/3.5.1/jquery.js'
dynamicLoadJs(url);