简单的js调试工具函数
最近做项目,有时候需要打印出程序运行到那里,于是就写了个debug的小工具,留以自用,也正在尝试着用这种方式写程序,觉得比起以前,我的js有了点进步。可喜可贺
/*
debug 调试js by jun @2010.8.26
使用,放到页面最下面
*/
var debug = (function(){
var count=0,
debugcont,
clear,
log=function(e){
var buginfotag = document.createElement('p');
buginfotag.style.cssText = "margin:0;padding:0";
var buginfo = document.createTextNode(e+'-----'+count);
buginfotag.appendChild(buginfo);
debugcont.appendChild(buginfotag);
setTimeout(function() {
debugcont.scrollTop = debugcont.scrollHeight;
},
200)
count++;
};
init=(function(){
var debug = document.createElement('div');
debugcont = document.createElement('div');
clear = document.createElement('button');
var cltext = document.createTextNode('清空');
debug.id = 'debuginfo';
debug.style.cssText = "position:absolute;right:5px;top:5px;width:300px;height:500px;border:1px solid #000000;overflow-y:auto;word-wrap:break-word;font-size:14px;";
document.body.appendChild(debug);
clear.id = 'cleardebug';
clear.appendChild(cltext)
debug.appendChild(clear);
debug.appendChild(debugcont);
clear.onclick=function(){
setTimeout(function(){
debugcont.innerHTML=''
count=0;
},0)
}
})();
return log;
})();


