When I try to execute this in jQuery I get $ctx.getContext is not a function
in firebug.
var $ctx = $( 开发者_如何学C'<canvas />', {width:'100', height:'100'} )
$widget.append($ctx)
$ctx.getContext('2d')
Any idea why I get this error? How do I dynamically create and initialize a canvas element?
$ctx
is a jQuery object. use $ctx[0].getContext('2d')
to get the context
If using excanvas you will need to use the following so it works in IE.
var canvas = $ctx[0];
if (canvas.getContext == undefined) {
return G_vmlCanvasManager.initElement(canvas).getContext("2d");
}
return canvas.getContext('2d')
first thing first , you need to check out if the following line is exist and the top of HTML document.
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML Strict//EN">
this line as a browser render policy excuted condition.
精彩评论