【问题标题】:Why doesn't this javascript code for a basic canvas operation work?为什么这个用于基本画布操作的 javascript 代码不起作用?
【发布时间】:2017-11-28 10:39:36
【问题描述】:

为什么下面的代码没有在屏幕上显示黑框。它为聊天室页面命名,因此至少开始部分有效......

<html>
<head>
<title>Chatroom</title>
</head>
<body>
<canvas id=“chatroom” width=“240 height=“400”></canvas>
<script>
const canvas= document.getElementById('chatroom');
const context=canvas.getContext('2d');

context.fillStyle ='#000';
context.fillRect(0,0,canvas.width,canvas.height);
</script>
</body>
</html>

谢谢!

【问题讨论】:

    标签: javascript html canvas


    【解决方案1】:

    查看属性。你没有正确引用它们。

    width="240"

    【讨论】:

      【解决方案2】:

      把你所有的“改成”:这些是不同的字符,你需要在html中使用第二个。

      您在 240 之后还缺少一个 "。

      【讨论】:

      • 谢谢!抱歉,您所说的“到”是什么意思?
      • 您使用的是字符“.您需要使用字符“。这些是不同的,也许您的字体没有显示它,但在我的字体上您可以看到细微的差别。
      猜你喜欢
      • 2012-02-22
      • 1970-01-01
      • 2013-02-03
      • 2017-08-26
      • 2013-12-19
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多