因此,我找到了一个有趣的模式,我想针对不同的数字编写一个自动化程序。在程序中,您可以输入n
和m
,它们现在还不那么重要。问题是,我无法在画布上绘画。我想知道我在做什么错。这是代码:
<!DOCTYPE html>
<html>
<head>
<title>oof</title>
<meta charset="UTF-8">
<script>
function lines(n, m) {
var canvas = document.getElementById("theCanvas");
var c = canvas.getContext("2d");
var cy = n * m;
var cx = 1;
c.moveTo(cx, cy);
c.lineTo(cx, cy + 5);
c.stroke();
}
lines(1);
</script>
</head>
<body>
<canvas id="theCanvas" height="32767" width="32767" />
</body>
</html>
Uncaught TypeError: Cannot read property 'getContext' of null
at lines (hmm.html:9)
at hmm.html:20