代码
提交代码
<!DOCTYPE html> <html> <head> <meta charset="utf-8"> <title>慕课网Wiki</title> <style> #imooc{ border:1px solid #ccc; } </style> </head> <body> <canvas id="imooc"></canvas> <script> // 根据id属性获取到canvas标签 const canvas = document.getElementById('imooc'); // 获取到canvas的 渲染上下文, 渲染上下文的概念后面有讲到 const ctx = canvas.getContext('2d'); ctx.fillStyle = 'green'; ctx.fillRect(10, 10, 150, 100); </script> </body> </html>
运行结果