简体   繁体   中英

JavaScript and HTML5 canvas (basic) issue

I am trying to learn how to use a canvas and i cannot for the life of me figure out why this basic code wont work does anyone know what I am doing incorrect?

jsfiddle

<canvas id="ctx" width="500" height="500" style="border:1px solid #000000"></canvas>
 <script >

 var canvas = document.getElementById("canvas");
 var ctx = canvas.getContext("2d");

 ctx.fillText = ("hey", 50, 50);

 </script>

You are passing the wrong ID to getElementById . Your canvas id is ctx not canvas . Use document.getElementById('ctx').

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM