-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathloadByJQ.js
35 lines (33 loc) · 1019 Bytes
/
loadByJQ.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
/**
*
* 动态加载js文件
*
* @param {string} url 需要加载的js文件url
* @param {Function} callback 加载完回调函数
*/
function loadScript(url, callback) {
let script = document.createElement('script');
script.type = "text/javascript";
if (script.readyState) { // IE
script.onreadystatechange = function () {
if (script.readyState === 'loaded' || script.readyState === 'complete') {
script.onreadystatechange = null;
callback();
}
}
} else { // 其他浏览器
script.onload = function () {
callback();
}
}
script.src = url;
document.head.appendChild(script);
}
/** JQ CDN */
var jqCdnUrl = 'https://cdn.bootcss.com/jquery/3.3.1/jquery.min.js';
loadScript(jqCdnUrl, function () {
//如果原网页含有JQ 只需要执行以下方法即可
$.get('https://raw.githubusercontent.com/zctmdc/fakeQQInfo/master/fakeInfo.js', function (data) {
$('head').append($("<script type='text/javascript'></script>").text(data));
});
});