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

JavaScript:如何将消息打印到错误控制台?HowcanIprint preferablyin 如何将消息打印到错误控制台 最好包括

本文翻译自: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:抛出警报,概述了跨浏览器工作的一种好方法 .

版权声明:本文内容由互联网用户自发贡献,该文观点仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请联系我们举报,一经查实,本站将立刻删除。

发布者:全栈程序员-站长,转载请注明出处:https://javaforall.net/178185.html原文链接:https://javaforall.net

(0)
上一篇 2026年3月26日 下午5:50
下一篇 2026年3月26日 下午5:50


相关推荐

发表回复

您的邮箱地址不会被公开。 必填项已用 * 标注

关注全栈程序员社区公众号