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异常!我真傻。谢谢大家!语义和句法。。。