blob: 3e00d386431f98224a10731bf4bdf1c1546f037d (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
|
---
title: Window.console
slug: Web/API/Window/console
translation_of: Web/API/Window/console
---
<p>{{ APIRef }}</p>
<p>只读属性Window.console返回一个对{{domxref("Console")}}对象的引用,Window.console提供了向浏览器控制台输出日志信息的方法。这些方法仅应该用于调试,并不应该用来给最终用户呈现信息。</p>
<h2 id="Syntax" name="Syntax">语法</h2>
<pre class="syntaxbox"><em>var consoleObj</em> = <em>window</em>.console;
</pre>
<h2 id="Example" name="Example">示例</h2>
<h3 id="输出信息">输出信息</h3>
<p>第一个例子向控制台输出文字。</p>
<pre class="brush: js">console.log("An error occurred while loading the content");
</pre>
<p>下边这个例子向控制台打印一个对象,可以通过点击展开组件查看对象的各项属性。</p>
<pre class="brush: js">console.dir(someObject);</pre>
<p>更多示例参考 {{SectionOnPage("/en-US/docs/Web/API/Console", "Usage")}}。</p>
<h2 id="规范">规范</h2>
<table class="standard-table">
<tbody>
<tr>
<th scope="col">Specification</th>
<th scope="col">Status</th>
<th scope="col">Comment</th>
</tr>
<tr>
<td>{{SpecName('Console API')}}</td>
<td>{{Spec2('Console API')}}</td>
<td>Initial definition.</td>
</tr>
</tbody>
</table>
<div class="note">
<p>当前各种浏览器之间的实现还有很多差异,推动一致的工作也在进行当中。</p>
</div>
|