From 33058f2b292b3a581333bdfb21b8f671898c5060 Mon Sep 17 00:00:00 2001 From: Peter Bengtsson Date: Tue, 8 Dec 2020 14:40:17 -0500 Subject: initial commit --- files/zh-cn/web/api/console/timelog/index.html | 102 +++++++++++++++++++++++++ 1 file changed, 102 insertions(+) create mode 100644 files/zh-cn/web/api/console/timelog/index.html (limited to 'files/zh-cn/web/api/console/timelog/index.html') 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 +--- +
{{APIRef("Console API")}}
+ +
在控制台输出计时器的值,该计时器必须已经通过 {{domxref("console.time()")}} 启动。
+ +
+ +

参阅文档中的 Timers 部分获取详细说明和示例。 

+ +

{{AvailableInWorkers}}

+ +

语法

+ +
console.timeLog(label);
+
+ +

参数

+ +
+
label
+
计时器索引。
+
+ +

返回值

+ +

如果没有传入 label 参数,则以 default: 作为引导返回数据:

+ +
default: 1042ms
+ +

如果传入了一个已经存在的 label ,则会以 label:  作为引导返回数据:

+ +
label: 1242ms
+ +

异常

+ +

如果计时器未启动, timeLog() 会返回一个警告:

+ +
Timer “default” doesn’t exist.
+ +

如果传入的 label 索引没有与之对应的计时器,则返回如下警告:

+ +
Timer “timer name” doesn’t exist. 
+ +

示例

+ +
console.time("answer time");
+alert("Click to continue");
+console.timeLog("answer time");
+alert("Do a bunch of other stuff...");
+console.timeEnd("answer time");
+
+ +

上例中的输出分别显示了用户从打开页面到关闭第一个 alert 和第二个 alert 框的时间间隔:

+ +

+ +

注意:使用 timelog() 输出计时器的值会显示计时器名称。使用 timeEnd() 停止也会显示计时器名称和输出计时器的值,并且,最后的 " - timer ended" 可以清楚的显示计时器不再计时的信息。

+ +

规范

+ + + + + + + + + + + + + + + + +
规范状态注释
{{SpecName("Console API", "#timelog", "console.timeLog()")}}{{Spec2("Console API")}}Initial definition
+ +

浏览器兼容性

+ +
+ + +

{{Compat("api.Console.timeLog")}}

+
+ +

相关文档

+ + -- cgit v1.2.3-54-g00ecf