Creates a new inline group in the Web 控制台 log. This indents following console messages by an additional level, until console.groupEnd() 被调用。

注意: 此特征可用于 Web 工作者 .

句法

console.group([label]);
					

参数

label
Label for the group. Optional. (Chrome 59 tested) Does not work with console.groupEnd() .

在控制台中使用组

Requires Gecko 9.0(Firefox 9.0 / Thunderbird 9.0 / SeaMonkey 2.6)

You can use nested groups to help organize your output by visually associating related messages. To create a new nested block, call console.group() console.groupCollapsed() method is similar, but the new block is collapsed and requires clicking a disclosure button to read it.

注意: From Gecko 9 until Gecko 51, the groupCollapsed() method was the same as group() . Collapsed groups are fully supported starting in Gecko 52. See bug 1088360 .

To exit the current group, call console.groupEnd() 。例如,给出这样的代码:

console.log("This is the outer level");
console.group();
console.log("Level 2");
console.group();
console.log("Level 3");
console.warn("More of level 3");
console.groupEnd();
console.log("Back to level 2");
console.groupEnd();
console.log("Back to the outer level");
						

输出看起来像这样:

A screenshot of messages nested in the console output.

在控制台中使用组 在文档编制的 console 了解更多细节。

规范

规范 状态 注释
控制台 API
The definition of 'console.group()' in that specification.
实时标准 初始定义

浏览器兼容性

The compatibility table on this page is generated from structured data. If you'd like to contribute to the data, please check out https://github.com/mdn/browser-compat-data and send us a pull request. 更新 GitHub 上的兼容性数据
桌面 移动
Chrome Edge Firefox Internet Explorer Opera Safari Android webview Chrome for Android Firefox for Android Opera for Android Safari on iOS Samsung Internet
group Chrome 1 Edge 12 Firefox 4 IE 11 Opera Yes Safari 4 WebView Android 37 Chrome Android 18 Firefox Android 4 Opera Android ? Safari iOS ? Samsung Internet Android 1.0

图例

完整支持

完整支持

兼容性未知 ?

兼容性未知

另请参阅

元数据

  • 最后修改: