代碼
提交代碼
<!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>
運行結果