<script> var canvasWidth = 800; var canvasHeight = 600;</script>我想使用这些变量来设置 HTML 标记的属性 这在语法上不正确,但显示了我想如何使用这些变量:<canvas id="context" width='canvasWidth' height='canvasHeight' style="border: 1px solid #000000;"></canvas>我该怎么做?这甚至是好的做法吗?您建议我如何控制画布大小以及使用 JavaScript 清除画布?
2 回答
![?](http://img1.sycdn.imooc.com/533e4d660001312002000200-100-100.jpg)
白衣染霜花
TA贡献1796条经验 获得超10个赞
var canvasWidth = 800;
var canvasHeight = 600;
document.getElementById('context').width = canvasWidth;
document.getElementById('context').height = canvasHeight;
<canvas id="context" style="border: 1px solid #000000;"></canvas>
添加回答
举报
0/150
提交
取消