javascript console

console.log(object[, object, ...])
在控制台输出一条消息。如果有多个参数,输出时会用空格隔开这些参数。

第一个参数可以是一个包含格式化占位符输出的字符串,例如:

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);

如果参数是一个Javascript对象,那么在控制台输出的就不是静态文字,而是一个可交互的超链接,点击超链接可以查看该对象的HTML, CSS, Script, DOM窗口,可用格式化字符串%o代替Javascript对象。

console.log("Body tag is %o", document.body);

格式化字符串列表:

格式化字符串类型
%s 字符串
%d, %i 整型(暂不支持数字型)
%f 浮点型 (暂不支持数字型) 
%o 链接对象

console.debug(object[, object, ...])
在控制台输出一条消息,包含一个指向代码调用位置的超链接。假如是直接在控制台输入该命令,就不会出现超链接(和console.log()一样)。

console.info(object[, object, ...])
在控制台输出一条带有“信息”图标的消息和一个指向代码调用位置的超链接。

console.warn(object[, object, ...])
在控制台输出一条带有“警告”图标的消息和一个指向代码调用位置的超链接。

console.error(object[, object, ...])
在控制台输出一条带有“错误”图标的消息和一个指向代码调用位置的超链接。

console.assert(expression[, object, ...])
测试表达式expression是否为真。如果不是真,会在控制台写一条消息并抛出异常

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.group打开的块。

console.time(name)
创建一个名字为name的计时器,调用console.timeEnd(name)停止计时器并输出所耗时间(毫秒)。

console.timeEnd(name)
停止同名的计时器并输出所耗时间(毫秒)。

console.profile([title])
打开Javascript性能测试开关。可选参数title会在打印性能测试报告时在报告的开头输出。

console.profileEnd()
关闭Javascript性能测试开关并输出报告。

console.count([title])

Writes the number of times that the line of code where count was called was executed. The optional argument title will print a message in addition to the number of the count.

posted on 2010-10-07 21:52  次龙  阅读(11106)  评论(0编辑  收藏  举报

导航