Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/ember.js/4.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 canvas.getContext做的不多_Javascript - Fatal编程技术网

Javascript canvas.getContext做的不多

Javascript canvas.getContext做的不多,javascript,Javascript,我有这样的代码,我将警报放在其中用于测试目的!: <html> <head> </head> <body> <canvas width=750,height=860,id="maze">HTML5?</canvas> <noscript>Javascript?</noscript> <script> alert("hello! (1)");

我有这样的代码,我将警报放在其中用于测试目的!:

<html>
<head>
</head>
<body>
    <canvas width=750,height=860,id="maze">HTML5?</canvas>
    <noscript>Javascript?</noscript>
    <script>
        alert("hello! (1)");
        var canvas = document.getElementById("maze");

        alert("hello! (2)");
        var context = canvas.getContext("2d");

        alert("hello! (3)");
    </script>
</body>
第一个和第二个警报发出。第三个没有。我是否忽略了一些显而易见的事情?

改变这一点:

<canvas width=750,height=860,id="maze">HTML5?</canvas>
为此:

<canvas width="750" height="860" id="maze">HTML5?</canvas>

从HTML标记中删除逗号:

<canvas width=750 height=860 id="maze">HTML5?</canvas>

使用console.log进行调试,然后通过检查变量的值学习调试。使用错误控制台查看您得到的canvas is undefined异常!我真傻。谢谢大家!语义和句法。。。