Javascript HTML画布不显示我的矩形 window.onload=函数(){ var canvas=document.getElementById(“映射”), c=canvas.getContext(“2d”); c、 fillStyle=“黑色”; c、 fillRect(0,0,canvas.width,canvas.height); c、 fillStyle=“红色”; c、 fillRect=(20,30,50,250); c、 fillSyle=“白色”; c、 fillRect=(50,50,25,25); }; 您需要更新的浏览器才能查看此页面!
我只是对画布做了一些修补,试图了解它是如何工作的。然而,我正在观看的教程视频显示了c.fillRect和c.fillStyle的编码格式与我在代码中显示的格式完全相同,但我的屏幕仅显示第一组指令中的黑色矩形。Javascript HTML画布不显示我的矩形 window.onload=函数(){ var canvas=document.getElementById(“映射”), c=canvas.getContext(“2d”); c、 fillStyle=“黑色”; c、 fillRect(0,0,canvas.width,canvas.height); c、 fillStyle=“红色”; c、 fillRect=(20,30,50,250); c、 fillSyle=“白色”; c、 fillRect=(50,50,25,25); }; 您需要更新的浏览器才能查看此页面!,javascript,canvas,Javascript,Canvas,我只是对画布做了一些修补,试图了解它是如何工作的。然而,我正在观看的教程视频显示了c.fillRect和c.fillStyle的编码格式与我在代码中显示的格式完全相同,但我的屏幕仅显示第一组指令中的黑色矩形。fillRect的语法是c.fillRect(…),而不是c.fillRect=(…)。将最近两次通话与第一次通话进行比较 此外,您最后的fillStyle被错误输入为fillSyle window.onload=函数(){ var canvas=document.getElementByI
fillRect
的语法是c.fillRect(…)
,而不是c.fillRect=(…)
。将最近两次通话与第一次通话进行比较
此外,您最后的fillStyle
被错误输入为fillSyle
window.onload=函数(){
var canvas=document.getElementById(“映射”),
c=canvas.getContext(“2d”);
c、 fillStyle=“黑色”;
c、 fillRect(0,0,canvas.width,canvas.height);
c、 fillStyle=“红色”;
c、 fillRect(20,30,50,250);
c、 fillStyle=“白色”;
c、 fillRect(50,50,25,25);
};
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<script>
window.onload = function(){
var canvas = document.getElementById("map"),
c = canvas.getContext("2d");
c.fillStyle = "black";
c.fillRect(0, 0, canvas.width, canvas.height);
c.fillStyle = "red";
c.fillRect = (20, 30, 50, 250);
c.fillSyle = "white";
c.fillRect = (50,50,25,25);
};
</script>
</head>
<body>
<canvas id="map" width="800" height="400">
<img src="images/sad dinosaur.jpg" />
You will need an updated browser to view this page!
</canvas>
</body>
</html>