我似乎无法弄清楚为什么没有使用此代码显示画布,我有以HTML格式链接的JS文件
// HTML文件
<!DOCTYPE html>
<hmtl>
<head>
<link href = "style.css" rel = "stylesheet">
<canvas id = "gameCanvas" width = "800" height = "600" style = "border: 1px"></canvas>
</head>
<body>
<script src = "main.js">
</script>
</body>
</html>
// JAVASCRIPT file
function canvas(){
var canvas = document.getElementById("gameCanvas");
var cavasContext = canvas.getContext("2d");
canvasContext.fillStyle = "black";
canvasContext.fillRect = (0, 0, canvas.width, canvas.height);
}
canvas();