【发布时间】:2022-08-24 03:44:14
【问题描述】:
我不明白为什么这段代码给了我第 11 行错误
if (canvas.getContext) {...
<!DOCTYPE html>
<html lang=\"en-US\">
<head>
<meta charset=\"UTF-8\"/>
<title>Peripheral vision checker</title>
<script type=\"application/javascript\">
function draw() { if (canvas.getContext) {
const canvas = document.getElementById(\'canvas\');
if (canvas.getContext) {
const ctx = canvas.getContext(\'2d\');
function getRandomInt(max) {
return Math.floor(Math.random() * max);
}
var x = 1000;//will be equal to window height
var y = 100;//will be equal to window width
ctx.arc(getRandomInt(x), getRandomInt(y), 10, 0, 2 * Math.PI);
console.log(getRandomInt(x) + \" \" + getRandomInt(y));//just temporary to see they work
ctx.fill();
}
}
</script>
</head>
<h1>Peripheral vision checker</h1>
<body onload=\"draw();\">
<canvas id=\"canvas></canvas>
</body>
</html>
没有CSS。