chrome开发者工具中console的用途

来源:互联网 发布:淘宝美工修图视频 编辑:程序博客网 时间:2024/05/16 08:52

chrome开发者工具中Console可以再任何面板中显示出来。可以点击下面的按钮,也可以按ESC键。

Console的用途很多,不像其他面板只有一种用途。

Console中可以使用firebug的命令行API。

常用的命令:

(1)$("id")显示特定id的元素;

(2)$0,返回上一个审查(Inspect)的元素。

(3)$1,返回倒数第二个审查的元素。

(4)dir(object),显示DOM对象的属性,将DOM看做javascript对象。

(5)dirxml(node),以html形式显示节点,和elements面板中看到的一样。

chrome的介绍中没有找到完整的API介绍。可以参考firebug的。

help

Returns a list of Command Line API commands including short descriptions. 

 $(id)

Returns a single element with the given id.

Warning: it will ultimately change to return the first match for the given CSS selector.

$$(selector)

Returns an array of elements that match the given CSS selector.

$x(xpath)

Returns an array of elements that match the given XPath expression.

$0

Represents the last element selected via the Inspector.

$1

Represents the second last element selected via theInspector.

$n(index)

Returns one of the 5 last elements selected via theInspector. This method takes one required parameterindex, which represents the index of the element (starting at 0).

dir(object)

Prints an interactive listing of all properties of the object. This looks identical to the view that inside theDOM Panel.

dirxml(node)

Prints the XML source tree of an HTML or XML element. This looks identical to the view inside theHTML Panel. You can click on any node to inspect it in the HTML panel.

cd(window)

By default, command line expressions are relative to the top-level window of the page. cd() allows you to use the window of a frame in the page instead.

 clear()

Clears the console.

copy(object)

Copies the given parameter to the clipboard. This can be a return value of a function or an object.

inspect(object[, panelName])

Inspects an object in the most suitable panel, or the panel identified by the optional argumentpanelName.

The available tab names are "html", "stylesheet", "script", and "dom".

keys(object)

Returns an array containing the names of all properties of the object.

values(object)

Returns an array containing the values of all properties of the object.

include(url[, alias]) / include(alias)

Includes a remote script.

debug(fn)

Adds a breakpoint on the first line of a function.

 undebug(fn)

Removes the breakpoint on the first line of a function.

monitor(fn)

Turns on logging for all calls to a function.

unmonitor(fn)

Turns off logging for all calls to a function.

monitorEvents(object[, types])

Turns on logging for all events dispatched to an object. The optional argumenttypes may define specific events or event types to log.

unmonitorEvents(object[, types])

Turns off logging for all events dispatched to an object. The optional argumenttypes may define specific events or event families, for which to turn logging off.

For a list of available event families see monitorEvents(object[, types]).

profile([title])

Turns on the JavaScript profiler. The optional argumenttitle contains the text to be printed in the header of the profile report.

profileEnd()

Turns off the JavaScript profiler and prints its report.

table(data[, columns])

This is a shortcut for console.table().

traceCalls(fn)

Enables tracing of specific function calls.

untraceCalls(fn)

Disables tracing of specific function calls.

traceAll()

Enables tracing of function calls for a whole context.

untraceAll()

Disables tracing of function calls for a whole context.

 

详细地址:https://getfirebug.com:80/wiki/index.php/Command_Line_API

 

 

原创粉丝点击