我最近开始使用 HTML 编程,所以在我将脚本添加到代码中后,我不知道如何重新加载页面以使脚本运行



http://localhost:63342/untitled1exercise.1html/exercise1.html?_ijt=kk8leu22fhfgiu9fi47k34bc04

<!doctype html>
<html>
<head>
</title>Hello world I'm Nour Belhassen and I am in the process of making a game<title/>
</head>
<body>
</h1>Hello world I'm Nour Belhassen and I am in the process of making a game <h1/>
<canvas id="asteroids" width="400" height="400"></canvas>
<script>
var canvars = document.getElementById("asteroids")
var context = canvas.getContext("2d")
context.strokeStyle = 'dimegrey';
context.lineWidth = 5;
context.rect(75,75,250,250);
context.stroke();
// this is a comment, it has no effect!!!
</script>
</body>
</html>

为什么不尝试按键盘上的F5来重新加载页面?

在Windows上,您也可以尝试CTRLr。在MacOS上,它是CMDr

您有一个打字错误。

// canvars
var canvars = document.getElementById("asteroids")
// canvas without 'r'
var context = canvas.getContext("2d")

这就是你的脚本失败的原因

您可以查看JS中的DOM内容加载事件。

相关内容

最新更新