什么是console.log? [英] What is console.log?
问题描述
console.log
有什么用?
请通过代码示例解释如何在JavaScript中使用它。
Please explain how to use it in JavaScript, with a code example.
推荐答案
这不是jQuery功能,而是用于调试目的的功能。例如,当事情发生时,您可以将某些内容记录到控制台。例如:
It's not a jQuery feature but a feature for debugging purposes. You can for instance log something to the console when something happens. For instance:
$('#someButton').click(function() {
console.log('#someButton was clicked');
// do something
});
然后你会看到点击#someButton
当您点击按钮时,在Firebug的控制台选项卡(或其他工具的控制台 - 例如Chrome的Web Inspector)中。
You'd then see #someButton was clicked
in Firebug’s "Console" tab (or another tool’s console — e.g. Chrome’s Web Inspector) when you would click the button.
由于某些原因,控制台对象可能不可用。然后你可以检查它是否 - 这很有用,因为你在部署到生产时不必删除你的调试代码:
For some reasons, the console object could be unavailable. Then you could check if it is - this is useful as you don't have to remove your debugging code when you deploy to production:
if (window.console && window.console.log) {
// console is available
}
这篇关于什么是console.log?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!