JavaScript console.group() 方法
实例
在控制台中创建一组消息:
<!DOCTYPE html><html><body><p>按键盘上的 F12 键可在 console 控制台中查看消息。</p><script>console.log("Hello world!");console.group();console.log("Hello again, this time inside a group!");</script></body></html>
定义与用法
console.group() 方法指示消息组的开始。之后,所有消息都将写入此消息组中。
提示:使用 console.groupEnd() 方法来结束消息组。
提示:使用 console.groupCollapsed() 隐藏消息组。
浏览器支持
表中的数字指定完全支持该方法的第一个浏览器版本。
| 方法 | |||||
|---|---|---|---|---|---|
| console.group() | Yes | 11.0 | 4.0 | 4.0 | Yes |
语法
console.group(label)
参数值
| 参数 | 类型 | 描述 |
|---|---|---|
| label | String | 可选。消息组的标签 |
更多实例
实例
使用 console.groupEnd() 方法结束消息组:
<!DOCTYPE html><html><body><p>使用 console.groupEnd() 方法结束消息组。</p><p>按键盘上的 F12 键可在 console 控制台中查看消息。</p><script>console.log("Hello world!");console.group();console.log("Hello again, this time inside a group!");console.groupEnd();console.log("and we are back.");</script></body></html>
实例
为一个消息组指定标签:
<!DOCTYPE html><html><body><p>带 label 的消息组</p><p>按键盘上的 F12 键可在 console 控制台中查看消息。</p><script>console.log("Hello world!");console.group("myLabel");console.log("Hello again, this time inside a group, with a label!");</script></body></html>