月小升

一个13年的开发老兵。

  博客园  :: 首页  :: 新随笔  :: 联系 :: 订阅 订阅  :: 管理

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/

posted on 2012-09-03 10:59  月小升  阅读(376)  评论(0编辑  收藏  举报