![](/img/trans.png)
[英]Why can't my javascript redirect the following code, I've tried multiple solution that i found in StackOverFlow
[英]I've tried setting up my Canvas in JavaScript and it isn't working
我已经重新启动了大约 5 次,但没有用。 我正在尝试设置我的 canvas。第一部分是 js 文件中的代码,第二部分是我放入 HTML 文件中的代码。
记者:
var canvas;
var ctx;
var w = 1000;
var h = 600;
function setUpCanvas(){
canvas = document.querySelector("#myCanvas");
ctx = canvas.getContext("2d");
canvas.width = w;
canvas.height = h;
canvas.style.border = "5px dotted orange";
HTML:
<!DOCTYPE html>
<html>
<head>
<link rel ="stylesheet" type = "text/css" href = "m4.css">
</head>
<body>
<div id = "container">
<h1> module 4 : arrays and loops</h1>
<canvas id = "myCanvas"></canvas>
</div>
<script src = "m4.js"></script>
</body>
</html>
简单的答案,它的工作原理。 如需证明,请访问
https://loading.hermanboxcar5.repl.co
好的,如果您在该网站上按 ctrl u,它会为您提供您所做的代码(除了我的 js 文件名为script.js
)。 到目前为止,我最好的猜测是在你的 js 的最后一行之后放一个}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.