日本搞逼视频_黄色一级片免费在线观看_色99久久_性明星video另类hd_欧美77_综合在线视频

國內最全IT社區平臺 聯系我們 | 收藏本站
阿里云優惠2
您當前位置:首頁 > web前端 > jscript > 為調試JavaScript添加輸出窗口

為調試JavaScript添加輸出窗口

來源:程序員人生   發布時間:2013-11-16 22:47:26 閱讀次數:2805次

調試JavaScript是一件很麻煩的事,盡管有很多很好用的調試工具,但有時候想要跟蹤值的變化,但即不想中斷腳本執行,也不想用alert顯示值信息,這種情況下,一般的做法是在頁面上添加一個DIV或者其它元素,然后再往里面添加調試信息。雖然不是很復雜的實現,但每次都要這樣就會很麻煩,所以我寫了一小段腳本,用來自動生成這個輸出窗口。

window.Babu = {};

Babu.Debugging = {};

Babu.Debugging.writeLine = function(format, arg1, arg2) {

var console = Babu.Debugging._getConsole();

if (console.get_visible()) {
var msg = format;

if (typeof msg !== "undefined" && msg !== null) {
var index;
if (typeof msg === "string") {
var array = format.match(/{(d+)}/g);
if (array) {
for (var i = 0; i < array.length; i++) {
index = array[i];
index = parseInt(index.substr(1, index.length - 2)) + 1;
msg = msg.replace(array[i], arguments[index]);
}
}
}
}

var span = document.createElement("SPAN");
span.appendChild(document.createTextNode(msg));
console._output.appendChild(span);
console._output.appendChild(document.createElement("BR"));
span.scrollIntoView();

return span;
}
}

Babu.Debugging._getConsole = function() {
var console = Babu.Debugging._console;

if (!console) {
var div = document.createElement("DIV");
div.style.position = "fixed";
div.style.right = "3px";
div.style.bottom = "3px";
div.style.width = "350px";
div.style.height = "180px";
div.style.backgroundColor = "white";
div.style.color = "black";
div.style.border = "solid 2px #afafaf";
div.style.fontSize = "12px";

document.body.appendChild(div);

Babu.Debugging._console = console = div;

div = document.createElement("DIV");
div.style.backgroundColor = "#e0e0e0";
div.style.position = "absolute";
div.style.left = "0px";
div.style.right = "0px";
div.style.top = "0px";
div.style.height = "16px";
div.style.padding = "2px 2px";
div.style.margin = "0px";
console.appendChild(div);
console._toolbar = div;

div = document.createElement("DIV");
div.style.overflow = "auto";
div.style.whiteSpace = "nowrap";
div.style.position = "absolute";
div.style.left = "0px";
div.style.right = "0px";
div.style.top = "20px";
div.style.bottom = "0px";
div.style.height = "auto";
console.appendChild(div);
console._output = div;

var btn;

btn = document.createElement("SPAN");
btn.innerHTML = "收縮";
btn.style.margin = "0px 3px";
btn.style.cursor = "pointer";
console._toolbar.appendChild(btn);
btn.onclick = function() { if (console.get_collapsed()) console.expand(); else console.collapse(); }

btn = document.createElement("SPAN");
btn.innerHTML = "清除";
btn.style.margin = "0px 3px";
btn.style.cursor = "pointer";
console._toolbar.appendChild(btn);
btn.onclick = Babu.Debugging.clearConsole;

btn = document.createElement("SPAN");
btn.innerHTML = "關閉";
btn.style.cursor = "pointer";
btn.style.margin = "0px 3px";
console._toolbar.appendChild(btn);
btn.onclick = function() { Babu.Debugging.hideConsole(); }

console.get_visible = function() { return this.style.display !== "none" };
console.get_collapsed = function() { return !(!this._collapseState) };

console.collapse = function() {
if (!this.get_collapsed()) {
this._output.style.display = "none";
this._toolbar.childNodes[1].style.display = "none";
this._toolbar.childNodes[2].style.display = "none";
this._toolbar.childNodes[0].innerHTML = "展開";
this._collapseState = { width: this.style.width, height: this.style.height }
this.style.width = "30px";
this.style.height = "16px";
}
}

console.expand = function() {
if (this.get_collapsed()) {
this._output.style.display = "";
this._toolbar.childNodes[1].style.display = "";
this._toolbar.childNodes[2].style.display = "";
this._toolbar.childNodes[0].innerHTML = "收縮";
this.style.width = this._collapseState.width;
this.style.height = this._collapseState.height;
this._collapseState = null;

}
}
}

return console;
}

Babu.Debugging.showConsole = function() {
Babu.Debugging._getConsole().style.display = "";
}

Babu.Debugging.hideConsole = function() {
var console = Babu.Debugging._console;

if (console) {
console.style.display = "none";
}
}

Babu.Debugging.clearConsole = function() {
var console = Babu.Debugging._console;
if (console) console._output.innerHTML = "";
}

調用方法很簡單:

Babu.Debugging.writeLine("調試信息");

Babu.Debugging.writeLine("帶參數的調試信息:參數1={0},參數2={1}", arg1, arg2);

調用之后,會自動在窗口的右下角出現一個固定位置的窗口,并顯示相應的內容。效果圖請看下面:

轉自:http://www.cnblogs.com/effun/

生活不易,碼農辛苦
如果您覺得本網站對您的學習有所幫助,可以手機掃描二維碼進行捐贈
程序員人生
------分隔線----------------------------
分享到:
------分隔線----------------------------
關閉
程序員人生
主站蜘蛛池模板: 美女视频黄的免费的 | 国产精品av一区二区 | 91精品国产三级a在线观看 | 99精品久久99久久久久 | 日本一区二区三区免费看 | 亚洲国产福利 | 欧美综合在线视频 | 国产va| 久国产精品 | 亚洲精品乱码久久久久久写真 | 欧美一级毛片视频 | 欧美日韩亚洲国内综合网 | 日韩福利一区二区 | 欧美精品久 | 国产一区二区三区精品在线观看 | 中国一级片在线观看 | 99久久精品国产一区二区野战 | 中文字幕国产日韩 | 天天操夜夜草 | 九九九精品视频 | 成人区精品一区二区 | 久久精品久久综合 | 黄色免费在线视频 | 成人影视免费观看 | 精品久久精品久久 | 日本国产中文字幕 | 精品久久久久久综合日本 | 国产亚洲欧美一区二区 | 可以免费看av的网站 | 久久99精品久久久久久久久久久久 | 国产精品免费一区二区三区四区 | 久久久久久久网站 | 欧美精品一区二区久久 | 亚洲成人一区在线观看 | 亚洲 成人 一区 | 在线观看av网站 | 亚洲欧美激情在线 | 久久久久国产精品一区三寸 | 91精品啪在线观看国产81旧版 | 日本久久久 | 亚洲综合激情网 |