当前位置: 代码迷 >> Web前端 >> ie兑现console
  详细解决方案

ie兑现console

热度:271   发布时间:2012-10-19 16:53:37.0
ie实现console

调试js的时候 , ff,chrome,safari 浏览器中有console可以在控制台打印一些信息 , ie是没有这个console对象,故写了个console以便调试使用,仅仅实现了log方法。

<!doctype html>
<html>
<head>
<meta charset="utf-8"/>
</head>
<body>
112342134<br/>
112342134<br/>
112342134<br/>
112342134<br/>
112342134<br/>
112342134<br/>
</body>


<script>
if(!window.console){
	console = (function(){
		var instance = null;
		function Constructor(){
			this.div = document.createElement("console");
			this.div.id = "console";
			this.div.style.cssText = "filter:alpha(opacity=80);position:absolute;top:0px;left:0px;width:100%;border:1px solid #ccc;background:#eee;";
			document.body.appendChild(this.div);
		}
		Constructor.prototype = {
			log : function(str){
				var p = document.createElement("p");
				p.innerHTML = str;
				this.div.appendChild(p);
			}
		}
		function getInstance(){
			if(instance == null){
				instance =  new Constructor();
			}
			return instance;
		}
		return getInstance();
	})()
}

console.log("444");
console.log("555");
console.log("666");
console.log("777");

</script>
</html>

?

1 楼 flyash 2011-05-17  
IE9有了console

</body>
位置似乎不合适
  相关解决方案