clearRect() 方法清空指定矩形内的canvas画布。
<!DOCTYPE HTML>
<html>
<head><title>canvas 清空画布</title><meta charset="utf-8" /></head>
<body>
<div style="text-align:center;">
<canvas id="canvas" width="600" height="600"> </canvas>
</div>
<script type="text/javascript">
var canvas =document.getElementById("canvas");
var context =canvas.getContext("2d");
//清除画布的方法
context.clearRect(x,y,width,height);
//x 是要清除的矩形左上角的 x 坐标
//y 是要清除的矩形左上角的 y 坐标
//width 是要清除的矩形的宽度,以像素计
//height 是要清除的矩形的高度,以像素计
context.clearRect(0,0,600,600);
//清空整个canvas画布
</script>
</body>
</html>