日期:2014-05-16  浏览次数:20337 次

动态加载js 文件
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=windows-31j">
<title>Insert title here</title>
<script type="text/javascript">
	function importScript(scriptPath, callback) {
		var headTag = document.getElementsByTagName("head")[0];
		
		var scriptTag = document.createElement("script");
		scriptTag.type = "text/javascript";
		var isOver = false;
		scriptTag.onload = function() {
			if (isOver) {
				return;
			}
			isOver = true;
			callback();

		}
                // IE9/10同时支持onreadystatechange & onload
		scriptTag.onreadystatechange = function() {
			
			if (isOver) {
				return;
			}
			
			isOver = true;
			if (this.readyState == 'loaded' || this.readyState == 'complete') {
				callback();
			}
		};
		scriptTag.src = scriptPath;
		headTag.appendChild(scriptTag);
	}
	window.onload = function() {
		importScript("a.js", function() {test();});
	};
</script>
</head>
<body>

</body>
</html>