1
<canvas id="myCanvas" width="300" height="150" style="border:1px solid #d3d3d3;">
2
您的浏览器不支持 HTML5 canvas 标签。
3
</canvas>
4
<script>
5
var c = document.getElementById("myCanvas");
6
var ctx = c.getContext("2d");
7
// 红色矩形
8
ctx.beginPath();
9
ctx.lineWidth = "6";
10
ctx.strokeStyle = "red";
11
ctx.rect(5, 5, 290, 140);
12
ctx.stroke();
13
// 绿色矩形
14
ctx.beginPath();
15
ctx.lineWidth = "4";
16
ctx.strokeStyle = "green";
17
ctx.rect(30, 30, 50, 50);
18
ctx.stroke();
19
// 蓝色矩形
20
ctx.beginPath();
21
ctx.lineWidth = "10";
22
ctx.strokeStyle = "blue";
23
ctx.rect(50, 50, 150, 80);
24
ctx.stroke();
25
</script>