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);
安装Firebug,然后您可以使用console.log(...)
和console.debug(...)
等(请参阅文档以获取更多信息)。
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
您还可以将CSS添加到日志消息中:
console.log('%c My message here', "background: blue; color: black; padding-left:10px;");
Exceptions are logged into the JavaScript console. You can use that if you want to keep Firebug disabled.
function log(msg) {
setTimeout(function() {
throw new Error(msg);
}, 0);
}
Usage:
log('Hello World');
log('another message');
链接地址: http://www.djcxy.com/p/51872.html
上一篇: 比如谷歌浏览器的调试器