<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

        Html 5 canvas getElementById() returns null/undefined(Html 5 canvas getElementById() 返回 null/undefined)
            <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的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                  本站部分内容来源互联网,如果有图片或者内容侵犯了您的权益,请联系我们,我们会在确认后第一时间进行删除!

                  相关文档推荐

                  How does object-fit work with canvas element?(对象适合如何与画布元素一起使用?)
                  How to make rooftext effect and valley text effect in HTML5 (or Fabric.js)(如何在 HTML5(或 Fabric.js)中制作屋顶文字效果和山谷文字效果)
                  Draw border around nontransparent part of image on canvas(在画布上的图像不透明部分周围绘制边框)
                  dragging and resizing an image on html5 canvas(在 html5 画布上拖动图像并调整其大小)
                  What#39;s the difference between a boolean as primitive and a boolean as property of an object?(作为原始对象的布尔值和作为对象属性的布尔值有什么区别?)
                  I want to do animation of an object along a particular path(我想沿特定路径对对象进行动画处理)
                  <legend id='uKolW'><style id='uKolW'><dir id='uKolW'><q id='uKolW'></q></dir></style></legend>

                    • <bdo id='uKolW'></bdo><ul id='uKolW'></ul>
                    • <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>

                              <tbody id='uKolW'></tbody>