JavaScript代码片段

原创
2017/08/18 10:00
阅读数 38

1、动态加载JS文件。

var loadJs = function(d, a) {
	var c = document.getElementsByTagName("head")[0] || document.head
			|| document.documentElement;
	var b = document.createElement("script");
	b.setAttribute("type", "text/javascript");
	b.setAttribute("charset", "UTF-8");
	b.setAttribute("src", d);
	if (typeof a === "function") {
		if (window.attachEvent) {
			b.onreadystatechange = function() {
				var e = b.readyState;
				if (e === "loaded" || e === "complete") {
					b.onreadystatechange = null;
					a()
				}
			}
		} else {
			b.onload = a
		}
	}
	c.appendChild(b)
};
loadJs("http://changyan.sohu.com/upload/changyan.js", function() {
	window.changyan.api.config({
		appid : appid,
		conf : conf
	})
});

 

展开阅读全文
加载中
点击引领话题📣 发布并加入讨论🔥
打赏
0 评论
0 收藏
0
分享
返回顶部
顶部