JavaScript:如何将消息打印到错误控制台?

本文翻译自:JavaScript: How do I print a message to the error console?

How can I print a message to the error console, preferably including a variable? 如何将消息打印到错误控制台,最好包括变量?

For example, something like: 例如,类似于:

print('x=%d', x);

#1楼

参考:https://stackoom.com/question/glZ/JavaScript-如何将消息打印到错误控制台


#2楼

console.error(message); //gives you the red errormessage
console.log(message); //gives the default message
console.warn(message); //gives the warn message with the exclamation mark in front of it
console.info(message); //gives an info message with an 'i' in front of the message

You also can add CSS to your logging messages: 您还可以将CSS添加到日志消息中:

console.log('%c My message here', "background: blue; color: white; padding-left:10px;");

#3楼

安装Firebug ,然后您可以使用console.log(...)console.debug(...)等(有关详细信息,请参阅文档 )。


#4楼

如果您使用Firebug并且需要支持IE,Safari或Opera, Firebug Lite会为这些浏览器添加console.log()支持。


#5楼

WebKit Web Inspector还支持Firebug的控制台API(只是Dan的答案的一小部分)。


#6楼

One good way to do this that works cross-browser is outlined in Debugging JavaScript: Throw Away Your Alerts! 调试JavaScript:抛出警报,概述了跨浏览器工作的一种好方法 .

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值