<legend id='tVEak'><style id='tVEak'><dir id='tVEak'><q id='tVEak'></q></dir></style></legend>
        <bdo id='tVEak'></bdo><ul id='tVEak'></ul>
      <i id='tVEak'><tr id='tVEak'><dt id='tVEak'><q id='tVEak'><span id='tVEak'><b id='tVEak'><form id='tVEak'><ins id='tVEak'></ins><ul id='tVEak'></ul><sub id='tVEak'></sub></form><legend id='tVEak'></legend><bdo id='tVEak'><pre id='tVEak'><center id='tVEak'></center></pre></bdo></b><th id='tVEak'></th></span></q></dt></tr></i><div id='tVEak'><tfoot id='tVEak'></tfoot><dl id='tVEak'><fieldset id='tVEak'></fieldset></dl></div>

      <small id='tVEak'></small><noframes id='tVEak'>

        <tfoot id='tVEak'></tfoot>

        Html 5 canvas getElementById() 返回 null/undefined

        时间:2023-06-20
            <tbody id='8HYgo'></tbody>

          <small id='8HYgo'></small><noframes id='8HYgo'>

          <i id='8HYgo'><tr id='8HYgo'><dt id='8HYgo'><q id='8HYgo'><span id='8HYgo'><b id='8HYgo'><form id='8HYgo'><ins id='8HYgo'></ins><ul id='8HYgo'></ul><sub id='8HYgo'></sub></form><legend id='8HYgo'></legend><bdo id='8HYgo'><pre id='8HYgo'><center id='8HYgo'></center></pre></bdo></b><th id='8HYgo'></th></span></q></dt></tr></i><div id='8HYgo'><tfoot id='8HYgo'></tfoot><dl id='8HYgo'><fieldset id='8HYgo'></fieldset></dl></div>
            <bdo id='8HYgo'></bdo><ul id='8HYgo'></ul>

              • <tfoot id='8HYgo'></tfoot>
                <legend id='8HYgo'><style id='8HYgo'><dir id='8HYgo'><q id='8HYgo'></q></dir></style></legend>

                1. 本文介绍了Html 5 canvas getElementById() 返回 null/undefined的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                  问题描述

                  here's the code:

                  HTML:

                  <body onload="initializeMap()">
                      <div id="map_canvas" style="width:100%; height:100%; z-index:1"></div>
                      <canvas id="control" style="width:100%; height:100%; z-index:2">Does Not Support Canvas Element</canvas>
                  </body>
                  

                  Javascript:

                  <script type="text/javascript">
                      var canvas = document.getElementById('control');
                      var context = canvas.getContext('2d');
                  
                      function draw(){
                          context.font = "bold 12px sans-serif";
                          context.fillText("x", 248, 43);
                      }
                  </script>
                  

                  the draw function is called after initialization of the google map so the DOM should have already loaded by then, correct? What might have I done incorrectly?

                  解决方案

                  The DOM has already been loaded when the draw-function is called, that is correct.

                  But the var canvas = document.getElementById('control');-line is evaluated before that, because it is not in the draw-function. It is executed immediately in the <head> of the document BEFORE the elements have been rendered.

                  I would suggest you change your init function to something like that

                  var canvas,context;
                  function initializeMap() {
                     canvas = document.getElementById('control');
                     context = canvas.getContext('2d');
                  }
                  

                  这篇关于Html 5 canvas getElementById() 返回 null/undefined的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                  上一篇:无法克隆 OffscreenCanvas,因为它已分离 下一篇:在 KineticJS 中创建一个带有 mousedown 事件的矩形

                  相关文章

                  <legend id='uKolW'><style id='uKolW'><dir id='uKolW'><q id='uKolW'></q></dir></style></legend>

                    • <bdo id='uKolW'></bdo><ul id='uKolW'></ul>
                  1. <small id='uKolW'></small><noframes id='uKolW'>

                    1. <i id='uKolW'><tr id='uKolW'><dt id='uKolW'><q id='uKolW'><span id='uKolW'><b id='uKolW'><form id='uKolW'><ins id='uKolW'></ins><ul id='uKolW'></ul><sub id='uKolW'></sub></form><legend id='uKolW'></legend><bdo id='uKolW'><pre id='uKolW'><center id='uKolW'></center></pre></bdo></b><th id='uKolW'></th></span></q></dt></tr></i><div id='uKolW'><tfoot id='uKolW'></tfoot><dl id='uKolW'><fieldset id='uKolW'></fieldset></dl></div>
                      <tfoot id='uKolW'></tfoot>