源代码
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <title>编程字典</title> </head> <body> <canvas id="myCanvas" width="200" height="200" style="border:1px solid"> 你的浏览器不支持 HTML5 canvas 标签. </canvas> <script> var c = document.getElementById("myCanvas"); var ctx = c.getContext("2d"); ctx.fillStyle = "#92B901"; ctx.fillRect(50, 50, 100, 100); </script> <p><strong>注意:</strong> IE8 及以前版本不支持 canvas 标签</p> </body> </html>
运行结果