<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<title>每天一个JavaScript实例-canvas绘图</title>
<style>
.canvas{
width:600px;
height:500px;
}
</style>
<script>
window.onload = function(){
var imgcanvas = document.getElementById("imgcanvas");
if(imgcanvas.getContext){
var ctx = imgcanvas.getContext('2d');
ctx.fillStyle="rgba(255,0,0,.1)";
ctx.strokeStyle = "#000";
//第一个
ctx.fillRect(0,0,100,100);
ctx.strokeRect(0,0,100,100);
//第二个
ctx.fillRect(50,50,100,200);
//第三个
ctx.strokeRect(80,130,200,100);
}
}
</script>
</head>
<body>
<canvas class="canvas" id = "imgcanvas">
<p>画布</p>
</canvas>
</body>
</html>