<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>绘制矩形</title>
</head>
<body>
<canvas id="carvas" width="400" height="300" style="border:1px solid blue;"></canvas>
<script>
var c=document.getElementById('carvas');
var cxt=c.getContext("2d");
cxt.fillStyle="blue";
cxt.fillRect(0,0,400,300);
<html>
<head>
<meta charset="UTF-8">
<title>绘制矩形</title>
</head>
<body>
<canvas id="carvas" width="400" height="300" style="border:1px solid blue;"></canvas>
<script>
var c=document.getElementById('carvas');
var cxt=c.getContext("2d");
cxt.fillStyle="blue";
cxt.fillRect(0,0,400,300);