document.getElementById('canvas_main')获取绘图上下文总是失败
相关代码如下:function DrawSpecialClass(spclBodyInfList){
this.ud = new Object();
this.ud.pgraph = [ ];
this.ud.pdex = [ ];
this.ud.pindex = [ ];
this.ud.pvex = [ ];
this.ud.pval = [ ];
this.ud.mainCanvas;
this.ud.mainCt;
}
DrawSpecialClass.prototype.Initpage=function(){
this.ud.mainCanvas = document.getElementById('canvas_main');
this.ud.mainCt=this.ud.mainCanvas.getContext('2d');
this.ud.mainCt.strokeStyle = '#000';
this.ud.mainCt.clearRect(0,0,this.canvasWidth,this.canvasHeight);
};
var DrawSpl=new DrawSpecialClass(spclBodyInfList);
DrawSpl.Initpage();
且已经定义画布如下:
<canvas id="canvas_main" width="1200" height="600" style="border:10px solid #97694F;"></canvas>
提示错误:
this.ud.mainCanvas is null
[在此错误处中断] this.ud.mainCt=this.ud.mainCanvas.getContext('2d');