getContext在谷歌浏览器中,使用时要先加载canvas对象,否则会提示'getContext is null'

时间:2023-03-08 19:58:16
<body>
<canvas id="myCanvas" width="" height="" style="border:1px solid #c3c3c3;">
Your browser does not support the canvas element.
</canvas>
<script type="text/javascript">
var c = document.getElementById("myCanvas");
var cxt = c.getContext("2d");
cxt.fillStyle = "#FF0000";
cxt.fillRect(, , , );
</script> </body>
getContext在谷歌浏览器中,使用时要先加载canvas对象,否则会提示'getContext is null'