<!DOCTYPE html>
<!-- <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
-->
<html>
<head>
<title>Rectangles</title>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<style>
body {
background: #dddddd;
}
#canvas {
background: #eeeeee;
border: thin solid #aaaaaa;
}
</style>
</head>
<body>
<canvas id='canvas' width='600' height='400'>
Canvas not supported
</canvas>
<script>
var canvas=document.getElementById('canvas'),
context=canvas.getContext('2d');
context.lineWidth=5;
context.font='24px Helvetica';
context.fillText('点这儿',175,40);
//为指定矩形描边 如果后两个参数中任何一个为0,则画横线或者竖线,都为0则不绘制
context.strokeRect(75,100,200,200);
//填充矩形,如何后两个参数任意一个为0,则不绘制
context.fillRect(325,100,200,200);
context.canvas.onmousedown=function(e){
//清除指定区域的所有像素
context.clearRect(0,0,canvas.width,canvas.height);
};
</script>
</body>
</html>
演示地址:http://sandbox.runjs.cn/show/lw3bxgqv