IE下javascript的console方法

来源:互联网 发布:纪录片监守自盗知乎 编辑:程序博客网 时间:2024/05/01 02:38
FireFox 和 Chrome 下调试JS都有console,IE6下没有。特用此办法来兼容IE6.<br /><pre lang=‘‘html‘‘><!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></pre>
首发于http://java-er.com - http://java-er.com/blog/ie-console/
原创粉丝点击