【发布时间】:2014-08-16 22:54:52
【问题描述】:
我已阅读 this 和 this,但我的问题没有解决方案。如果我用 jQuery 创建一个画布,然后通过document.getElementById() 调用它,我可以调用getContext('2d') 并且它可以工作。像这样:
var ctx =
$('<canvas />')
.attr({
id: 'canvasMenuSmall',
width: '500px',
height: '500px'
})
.appendTo('body');
var c=document.getElementById("canvasMenuSmall"),
ctx=c.getContext('2d');
但是,如果我尝试立即在对象上调用 getContext('2d'),它不会出现错误 Uncaught TypeError: undefined is not a function:
var ctx =
$('<canvas />')
.attr({
id: 'canvasMenuSmall',
width: '500px',
height: '500px'
})
.appendTo('body')
.getContext('2d'); // error raised
怎么来的?
【问题讨论】: