diff options
author | Peter Bengtsson <mail@peterbe.com> | 2020-12-08 14:40:17 -0500 |
---|---|---|
committer | Peter Bengtsson <mail@peterbe.com> | 2020-12-08 14:40:17 -0500 |
commit | 33058f2b292b3a581333bdfb21b8f671898c5060 (patch) | |
tree | 51c3e392513ec574331b2d3f85c394445ea803c6 /files/zh-cn/web/api/console/timelog/index.html | |
parent | 8b66d724f7caf0157093fb09cfec8fbd0c6ad50a (diff) | |
download | translated-content-33058f2b292b3a581333bdfb21b8f671898c5060.tar.gz translated-content-33058f2b292b3a581333bdfb21b8f671898c5060.tar.bz2 translated-content-33058f2b292b3a581333bdfb21b8f671898c5060.zip |
initial commit
Diffstat (limited to 'files/zh-cn/web/api/console/timelog/index.html')
-rw-r--r-- | files/zh-cn/web/api/console/timelog/index.html | 102 |
1 files changed, 102 insertions, 0 deletions
diff --git a/files/zh-cn/web/api/console/timelog/index.html b/files/zh-cn/web/api/console/timelog/index.html new file mode 100644 index 0000000000..9dc87c6071 --- /dev/null +++ b/files/zh-cn/web/api/console/timelog/index.html @@ -0,0 +1,102 @@ +--- +title: Console.timeLog() +slug: Web/API/Console/timeLog +tags: + - API + - DOM + - Debugging + - Method + - Web Development + - console + - web console +translation_of: Web/API/Console/timeLog +--- +<div>{{APIRef("Console API")}}</div> + +<div>在控制台输出计时器的值,该计时器必须已经通过 {{domxref("console.time()")}} 启动。</div> + +<div></div> + +<p>参阅文档中的 <a href="/en-US/docs/Web/API/console#Timers">Timers</a> 部分获取详细说明和示例。 </p> + +<p>{{AvailableInWorkers}}</p> + +<h2 id="语法">语法</h2> + +<pre class="syntaxbox">console.timeLog(<em>label</em>); +</pre> + +<h3 id="参数">参数</h3> + +<dl> + <dt><code>label</code></dt> + <dd>计时器索引。</dd> +</dl> + +<h3 id="返回值">返回值</h3> + +<p>如果没有传入 label 参数,则以 default: 作为引导返回数据:</p> + +<pre>default: 1042ms</pre> + +<p>如果传入了一个已经存在的 <code>label</code> ,则会以 <code>label: </code> 作为引导返回数据:</p> + +<pre>label: 1242ms</pre> + +<h3 id="异常">异常</h3> + +<p>如果计时器未启动, <code>timeLog()</code> 会返回一个警告:</p> + +<pre><span class="message-body-wrapper"><span class="message-flex-body"><span class="devtools-monospace message-body">Timer “default” doesn’t exist.</span></span></span></pre> + +<p><span class="message-body-wrapper"><span class="message-flex-body"><span class="devtools-monospace message-body">如果传入的 label 索引没有与之对应的计时器,则返回如下警告:</span></span></span></p> + +<pre><span class="message-body-wrapper"><span class="message-flex-body"><span class="devtools-monospace message-body">Timer “timer name” doesn’t exist.</span></span></span> </pre> + +<h2 id="示例">示例</h2> + +<pre class="brush: js">console.time("answer time"); +alert("Click to continue"); +console.timeLog("answer time"); +alert("Do a bunch of other stuff..."); +console.timeEnd("answer time"); +</pre> + +<p>上例中的输出分别显示了用户从打开页面到关闭第一个 alert 和第二个 alert 框的时间间隔:</p> + +<p><a href="https://mdn.mozillademos.org/files/16741/timer_output.png"><img alt="" src="https://mdn.mozillademos.org/files/16741/timer_output.png" style="height: 354px; width: 537px;"></a></p> + +<p>注意:使用 <code>timelog()</code> 输出计时器的值会显示计时器名称。使用 <code>timeEnd()</code> 停止也会显示计时器名称和输出计时器的值,并且,最后的 " - timer ended" 可以清楚的显示计时器不再计时的信息。</p> + +<h2 id="规范">规范</h2> + +<table class="standard-table"> + <thead> + <tr> + <th scope="col">规范</th> + <th scope="col">状态</th> + <th scope="col">注释</th> + </tr> + </thead> + <tbody> + <tr> + <td>{{SpecName("Console API", "#timelog", "console.timeLog()")}}</td> + <td>{{Spec2("Console API")}}</td> + <td>Initial definition</td> + </tr> + </tbody> +</table> + +<h2 id="浏览器兼容性">浏览器兼容性</h2> + +<div> + + +<p>{{Compat("api.Console.timeLog")}}</p> +</div> + +<h2 id="相关文档">相关文档</h2> + +<ul> + <li><a href="http://www.opera.com/dragonfly/documentation/console/">Opera Dragonfly documentation: Console</a></li> +</ul> |