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

<body>
<canvas id="myCanvas" width="200" height="100" 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(0, 0, 150, 75);
    </script>

</body>
getContext在谷歌浏览器中,使用时要先加载canvas对象,否则会提示'getContext is null'
posted @ 2017-02-08 12:11  飞鱼0725  阅读(546)  评论(0)    收藏  举报