html console 查看dom,HTML DOM console.log()用法及代码示例

本文介绍了HTML中用于调试的console.log()方法,用于在控制台打印信息。通过示例展示了如何输出文本和对象,并列举了该方法在不同浏览器中的支持情况。示例包括输出字符串和对象到控制台,帮助开发者在程序测试期间跟踪重要消息。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

HTML中的console.log()方法用于在控制台中编写消息。它指示在测试任何程序期间的重要消息。该消息将作为参数发送到console.log()方法。

用法:

console.log( message )

参数:此方法接受单个参数消息,该消息是必需的,用于指定要在控制台上写入的信息。

以下程序说明了HTML中的console.log()方法:

范例1:

DOM console.log() Method

h1 {

color:green;

}

h2 {

font-family:Impact;

}

body {

text-align:center;

}

GeeksforGeeks

DOM console.log() Method

To view the message in the console

press the F12 key on your keyboard.

To view the message, double click

the button below:

View Message

function log_console() {

console.log

("GeeksforGeeks is a portal for geeks.");

}

输出:

740bd6614ab96e51b5d5dfc372d1eecb.png

控制台视图:

849484b9bf6d397dfddf9e2ced55612d.png

范例2:使用console.log()方法时显示对象

DOM console.log() Method

h1 {

color:green;

}

h2 {

font-family:Impact;

}

body {

text-align:center;

}

GeeksforGeeks

DOM console.log( ) Method

To view the message in the console

press the F12 key on your keyboard.

To view the message, double click

the button below:

View Message

function log_console() {

var MyElement = {

Product:"Coca Cola",

Type:"Beverage"

};

console.log(MyElement);

}

输出:

740bd6614ab96e51b5d5dfc372d1eecb.png

控制台视图:

06836b33184c8430f6d763a3949a929c.png

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

谷歌浏览器

Internet Explorer 8.0

Firefox 4.0

Opera

苹果浏览器

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值