在HTML5中,
Your browser does not support the HTML5 canvas tag.
// 获取 canvas 元素和 2D 渲染上下文
var canvas = document.getElementById("myCanvas");
var ctx = canvas.getContext("2d");
// 设置填充颜色为红色
ctx.fillStyle = "#FF0000";
// 绘制一个矩形:fillRect(x, y, width, height)
// x 和 y 是矩形左上角的坐标,width 和 height 是矩形的宽和高
ctx.fillRect(50, 50, 200, 100); // 绘制一个红色的矩形
在这个示例中,我们首先通过document.getElementById获取了