<html>
<head>
<meta charset="UTF-8">
<title>圖形的保存與恢復</title>
<script>
function draw(id){
var c=document.getElementById(id);
if(c==null)
return false;
var cxt=c.getContext("2d");
cxt.fillStyle="yellow";
cxt.save();
cxt.fillRect(50,50,100,100);
cxt.fillStyle="aqua";
cxt.save();
cxt.fillRect(200,50,100,100);
cxt.restore();//撤銷操作
cxt.fillRect(350,50,100,100);
cxt.restore();
cxt.fillRect(50,200,100,100);
}
</script>
</head>
<body οnlοad="draw('canvas')">
<canvas id="canvas" width="600" height="600" style="border:1px solid blue;"></canvas>
</body>
</html>