Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/459.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

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/html/87.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 html画布没有填充颜色_Javascript_Html_Canvas - Fatal编程技术网

Javascript html画布没有填充颜色

Javascript html画布没有填充颜色,javascript,html,canvas,Javascript,Html,Canvas,我一直在学习如何制作简单画布的教程。然而,画布并没有以任何颜色显示,即使我完全按照教程进行了操作。任何帮助。这让我心烦:/ <html> some text here <canvas id="gamecanvas" width="800" height="600></canvas>] <script> var Canvas; var canvasContext; window.onload = function() { console

我一直在学习如何制作简单画布的教程。然而,画布并没有以任何颜色显示,即使我完全按照教程进行了操作。任何帮助。这让我心烦:/

<html>

some text here

<canvas id="gamecanvas" width="800" height="600></canvas>]

<script>
var Canvas;
var canvasContext;

window.onload = function() {
   console.log("Hello world!");
   Canvas = document.getElementById("gamecanvas");
   canvasContext = canvas.getcontext('2d');
   canvasContext.fillStyle = 'red';
   canvasContext.fillRect(0,0,canvas.width,canvas.height);
 }     
 </script>
 </html>

这里有一些文字

语法错误太多

这是有效的

<html>

some text here

<canvas id="gamecanvas" width="800" height="600"></canvas>

    <script>
    var Canvas;
    var canvasContext;

    window.onload = function() {
      console.log("Hello world!");
      Canvas = document.getElementById("gamecanvas");
      canvasContext = Canvas.getContext('2d');
      canvasContext.fillStyle = 'red';
      canvasContext.fillRect(0,0,Canvas.width,Canvas.height);

    }     
    </script>
</html>

这里有一些文字
var帆布;
var canvasContext;
window.onload=函数(){
log(“你好,世界!”);
Canvas=document.getElementById(“gamecanvas”);
canvasContext=Canvas.getContext('2d');
canvasContext.fillStyle='red';
canvasContext.fillRect(0,0,Canvas.width,Canvas.height);
}     

您犯了两个错误

  • 你在混合
    canavs
    Canvas

  • 您编写的
    getContext
    带有无大写字母
    c


不要忘记,在JavaScript中,变量和方法名称是区分大小写的

因此
canavas
Canavs
不是同一变量,
getcontext('2d')
getcontext('2d')不是同一方法


这里有一把小提琴,我已经改正了错误:
var画布;
var canvasContext;
window.onload=函数(){
log(“你好,世界!”);
canvas=document.getElementById(“gamecanvas”);
canvasContext=canvas.getContext('2d');
canvasContext.fillStyle='red';
canvasContext.fillRect(0,0,canvas.width,canvas.height);
}
这里有一些文本

你的混音
画布
画布
。在js案例中,这个问题是如何获得选票的?一个有错误的代码怎么可能对某人有帮助呢?请随意将帮助你的答案标记为正确答案