調試JAVASCRIPT,不再用ALERT了 (二)

轉自:http://www.cnblogs.com/flykye/archive/2008/10/03/1303367.html

每個用Firefox加載的頁面,Firebug都添加了一個全局變量console,通過這個變量的若干方法,你可以通過腳本向控制檯輸出各種調試信息。

console.log(object[, object, ...])

往控制檯寫一條信息,可以有多個參數,甚至可以像printf那樣格式化出去,例如

console.log("The %s jumped over %d tall buildings", animal, count);

或者這樣:

console.log("The", animal, "jumped over", count, "tall buildings");
console.log("I am %s and I have:", myName, thing1, thing2, thing3);
下面是格式化參數表:

String Substitution Patterns
%s String
%d, %i Integer (numeric formatting is not yet supported)
%f Floating point number (numeric formatting is not yet supported)
%o Object hyperlink

console.debug(object[, object, ...])

向控制檯輸出一條信息,同時包含了跳往調用行的鏈接

console.info(object[, object, ...])

向控制檯輸出一條信息,前面顯示“信息”圖標,同樣包含了跳往調用行的鏈接

console.warn(object[, object, ...])

向控制檯輸出一條信息,前面顯示“警告”圖標,同樣包含了跳往調用行的鏈接

console.error(object[, object, ...])

向控制檯輸出一條信息,前面顯示“錯誤”圖標,同樣包含了跳往調用行的鏈接

console.assert(expression[, object, ...])

校驗是否符合表達式,如果不符合,將向控制檯輸出錯誤信息,並且拋出異常

console.dir(object)

輸出對象的所有屬性,可以在DOM標籤中看到詳細信息

console.dirxml(node)

輸出HTML或XML元素的XML代碼樹,可以再HTML中查看詳細的情況

console.trace()

Prints an interactive stack trace of JavaScript execution at the point where it is called.

The stack trace details the functions on the stack, as well as the values that were passed as arguments to each function. You can click each function to take you to its source in the Script tab, and click each argument value to inspect it in the DOM or HTML tabs.

console.group(object[, object, ...])

分組輸出,和console.groupEnd()配合使用,知道下一個console.groupEnd()出現,就閉合分組

console.groupEnd()

和console.group()配合使用

console.time(name)

創建一個定時器,知道調用console.time(name),才停止該定時器計時

console.timeEnd(name)

和console.time(name)配合使用

console.profile([title])

Turns on the JavaScript profiler. The optional argument title would contain the text to be printed in the header of the profile report

console.profileEnd()

Turns off the JavaScript profiler and prints its report

console.count([title])

 計數器,每執行一次,該title的值就累加1

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章