--- title: CanvasRenderingContext2D.clearHitRegions() slug: Web/API/CanvasRenderingContext2D/clearHitRegions translation_of: Web/API/CanvasRenderingContext2D/clearHitRegions ---
{{APIRef}} {{obsolete_header}}

CanvasRenderingContext2D.clearHitRegions() 是 Canvas 2D API 在画布中删除所有点击区域的方法。

语法

void ctx.clearHitRegions();

示例

使用 clearHitRegions 方法

这仅是一段简单的使用 clearHitRegions 方法的代码片段。

HTML

<canvas id="canvas"></canvas>

JavaScript

var canvas = document.getElementById("canvas");
var ctx = canvas.getContext("2d");

// set some hit regions
ctx.addHitRegion({id: "eyes"});
ctx.addHitRegion({id: "nose"});
ctx.addHitRegion({id: "mouth"});

// remove them altogether from the canvas
ctx.clearHitRegions();

规范描述

Specification Status Comment
{{SpecName('HTML WHATWG', "scripting.html#dom-context-2d-clearhitregions", "CanvasRenderingContext2D.clearHitRegions")}} {{Spec2('HTML WHATWG')}}

浏览器兼容性

{{CompatibilityTable}}

Feature Chrome Firefox (Gecko) Internet Explorer Opera Safari
Basic support {{CompatVersionUnknown}}[1] {{CompatGeckoDesktop(38)}} [2] {{ CompatNo }} {{ CompatNo }} {{ CompatNo }}
Feature Android Chrome for Android Firefox Mobile (Gecko) IE Mobile Opera Mobile Safari Mobile
Basic support {{ CompatNo }} {{ CompatNo }} {{CompatGeckoMobile(38)}} [2] {{ CompatNo }} {{ CompatNo }} {{ CompatNo }}

兼容性注解

参见