当我想获取画布的上下文时,我遇到了一个问题。这是HTML代码:
<canvas id="thecanvas" width="600" height="300"></canvas>
和Javascript:
var canvaso = document.getElementById('thecanvas');
if (!canvaso) {
alert('Error: Cannot find the canvas element!');
return;
}
if (!canvaso.getContext) {
alert('Error: Canvas context does not exist!');
return;
}
“canvaso”变量已正确加载,但在“canvaso.getContext”上失败:
Uncaught TypeError: Object #<HTMLDivElement> has no method 'getContext'
谢谢你的帮助。