Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/jquery/72.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 未捕获类型错误:无法读取属性';getContext';空的_Javascript_Jquery - Fatal编程技术网

Javascript 未捕获类型错误:无法读取属性';getContext';空的

Javascript 未捕获类型错误:无法读取属性';getContext';空的,javascript,jquery,Javascript,Jquery,这是我的HTML代码,显示画布: <canvas id="backgroundCanvas" width="550" height=600"></canvas> <canvas id="playerCanvas" width="550" height=600"></canvas <canvas id="enemiesCanvas" width="550" height=600"></canvas> 错误发生在第34行,其中

这是我的HTML代码,显示画布:

 <canvas id="backgroundCanvas" width="550" height=600"></canvas>
 <canvas id="playerCanvas" width="550" height=600"></canvas
 <canvas id="enemiesCanvas" width="550" height=600"></canvas>
错误发生在第34行,其中指出:

未捕获的TypeError:无法读取null的属性“getContext”


非常感谢您的帮助:)

因为您没有正确关闭
playerCanvas
的画布标记:

<canvas id="backgroundCanvas" width="550" height=600"></canvas>
<canvas id="playerCanvas" width="550" height=600"></canvas>
<canvas id="enemiesCanvas" width="550" height=600"></canvas>


您的javascript似乎在HTML加载完成之前运行。 如果可以使用jQuery,请将js放在其中

$( document ).ready(function() {
  // js goes in here.
});

您在中间画布上有一个
打字错误:
我没有上面的打字错误,因此出现了此错误。你的回答为我解决了这个问题。谢谢
$( document ).ready(function() {
  // js goes in here.
});