--- title: Performance.clearMarks() slug: Web/API/Performance/clearMarks translation_of: Web/API/Performance/clearMarks ---
{{APIRef("User Timing API")}}

clearMarks() 这个方法可以从浏览器的performance entry 缓存中移除声明的标记。如果调用这个方法时没有传递参数, 则所有带有{{domxref("PerformanceEntry.entryType","entry type")}}这类标记的{{domxref("PerformanceEntry","performance entries")}} 将从 performance entry 缓存区中被移除。

用法

performance.clearMarks();
performance.clearMarks(name);

参数

name {{optional_inline}}
{{domxref("DOMString")}} 表示时间戳的名字,如果没有提供这个参数, 则所有带有{{domxref("PerformanceEntry.entryType","entry type")}}这类标记的{{domxref("PerformanceEntry","performance entries")}} 将从 performance entry 缓存区中被移除。

返回值

void
 

例子

下面的例子演示clearMarks() 的两种用法。

function clear_mark(name) {
  if (performance.clearMarks === undefined) {
    console.log("performance.clearMarks Not supported");
    return;
  }
  //移除所有标记了此名称的peformance entry
  performance.clearMarks(name);
}
function clear_all_marks() {
  if (performance.clearMarks === undefined) {
    console.log("performance.clearMarks Not supported");
    return;
  }
  //从performance 缓冲区中移除所有标记的performance entry
  performance.clearMarks();
}

说明

说明 状态 备注
{{SpecName('User Timing Level 2', '#dom-performance-clearmarks', 'clearMarks()')}} {{Spec2('User Timing Level 2')}} Clarifies clearMarks().
{{SpecName('User Timing', '#dom-performance-clearmarks', 'clearMarks()')}} {{Spec2('User Timing')}} Basic definition.

浏览器兼容性

{{CompatibilityTable}}
Feature Chrome Edge Firefox (Gecko) Internet Explorer Opera Safari (WebKit)
Basic support {{CompatChrome(43.0)}} {{CompatVersionUnknown}} 41 10 33 {{CompatNo}}
Feature Android Android Webview Edge Firefox Mobile (Gecko) Firefox OS IE Phone Opera Mobile Safari Mobile Chrome for Android
Basic support {{CompatNo}} {{CompatChrome(46.0)}} {{CompatVersionUnknown}} 42 42 10 33 {{CompatNo}} {{CompatChrome(46.0)}}