Javascript jQuery 中的 console.log 是什么?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/3323940/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
What is console.log in jQuery?
提问by user398993
What is console.log? What is it used for in jQuery?
什么是console.log?它在 jQuery 中有什么用?
回答by zzzzBov
jQuery and console.logare unrelated entities, although useful when used together.
jQuery 和console.log是不相关的实体,虽然一起使用时很有用。
If you use a browser's built-in dev tools, console.logwill log information about the object being passed to the logfunction.
如果您使用浏览器的内置开发工具,console.log将记录有关传递给log函数的对象的信息。
If the console is not active, logging will not work, and may break your script. Be certain to check that the console exists before logging:
如果控制台未处于活动状态,日志记录将不起作用,并且可能会破坏您的脚本。在登录之前一定要检查控制台是否存在:
if (window.console) console.log('foo');
The shortcut form of this might be seen instead:
可以改为看到 this 的快捷形式:
window.console&&console.log('foo');
There are other useful debugging functions as well, such as debug, dirand error. Firebug's wiki lists the available functions in the console api.
还有其他有用的调试功能,例如debug、dir和error。Firebug 的 wiki 列出了控制台 api中的可用函数。
回答by Rich
It has nothing to do with jQuery, it's just a handy js method built into modern browsers.
它与 jQuery 无关,它只是现代浏览器中内置的一个方便的 js 方法。
Think of it as a handy alternative to debugging via window.alert()
将其视为通过 window.alert() 进行调试的便捷替代方案
回答by Matt Briggs
it will print log messages in your developer console (firebug/webkit dev tools/ie dev tools)
它将在您的开发者控制台中打印日志消息(firebug/webkit 开发工具/即开发工具)

