Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
145 views
in Technique[技术] by (71.8m points)

javascript - 什么是console.log?(What is console.log?)

What is the use of console.log ?

(console.log什么用?)

Please explain how to use it in JavaScript, with a code example.

(请通过代码示例说明如何在JavaScript中使用它。)

  ask by Mihir translate from so

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

It's not a jQuery feature but a feature for debugging purposes.

(它不是jQuery功能,而是用于调试的功能。)

You can for instance log something to the console when something happens.

(例如,您可以在发生某些情况时将某些内容记录到控制台。)

For instance:

(例如:)

$('#someButton').click(function() {
  console.log('#someButton was clicked');
  // do something
});

You'd then see #someButton was clicked in Firebug's “Console” tab (or another tool's console — eg Chrome's Web Inspector) when you would click the button.

(然后,您会#someButton was clicked Firebug的“控制台”选项卡(或其他工具的控制台,例如Chrome的Web Inspector)中看到#someButton was clicked#someButton was clicked 。)

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
}

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...