当前位置: 首页>>代码示例 >>用法及示例精选 >>正文


HTML DOM console.group()用法及代码示例


HTML中的console.group()方法用于在控制台中创建一组消息。它指示消息组的开始以及调用控制台后写入的所有消息。group()方法将写入消息组内部。标签作为可选参数发送到console.group()方法。

用法:

console.group( label )

参数:此方法接受可选的单个参数标签,用于指定组的标签。


以下示例程序旨在说明HTML中的console.group()方法:

范例1:

<!DOCTYPE html> 
<html> 
    <head>  
        <title>DOM console.group() Method</title>  
        <style>  
            h1 {  
                color:green;  
            }  
            h2 { 
                font-family:Impact; 
            } 
            body {  
                text-align:center;  
            }  
        </style>  
    </head> 
    <body> 
        <h1>GeeksforGeeks</h1>  
        <h2>DOM console.group() Method</h2>  
  
        <p> 
         To view the message in the console 
         press the F12 key on your keyboard. 
        </p> 
        <script> 
            console.log("GeeksforGeeks offers the following courses:"); 
            console.group(); 
            console.log("1. fork python"); 
            console.log("2. fork cpp"); 
            console.log("3. fork java"); 
            console.log("4. Interview preparation"); 
        </script> 
    </body> 
</html>                    

输出:

控制台视图:

范例2:将label参数与console.group()方法一起使用

<!DOCTYPE html> 
<html> 
    <head>  
        <title>DOM console.group() Method</title>  
        <style>  
            h1 {  
                color:green;  
            }  
            h2 { 
                font-family:Impact; 
            } 
            body {  
                text-align:center;  
            }  
        </style>  
    </head> 
    <body> 
        <h1>GeeksforGeeks</h1>  
        <h2>DOM console.group() Method</h2>  
        <p> 
         To view the message in the console  
         press the F12 key on your keyboard. 
        </p> 
        <script> 
            console.log("GeeksforGeeks offers the following courses:"); 
            console.group("Courses"); 
            console.log("1. fork python"); 
            console.log("2. fork cpp"); 
            console.log("3. fork java"); 
            console.log("4. Interview preparation"); 
        </script> 
    </body> 
</html>                    

输出:

控制台视图:

支持的浏览器:console.group()方法支持的浏览器如下:

  • 谷歌浏览器
  • Internet Explorer 11.0
  • Firefox 4.0
  • Opera
  • Safari 4.0


相关用法


注:本文由纯净天空筛选整理自Shubrodeep Banerjee大神的英文原创作品 HTML | DOM console.group() Method。非经特殊声明,原始代码版权归原作者所有,本译文未经允许或授权,请勿转载或复制。