求大神賜教
為什么一模一樣的代碼,我自己敲一遍,就運行不出來相同的效果?
var WINDOW_WIDTH=1024;
var WINDOW_HEIGHT=768;
var WINDOW_TOP=60;
var WINDOW_LEFT=30;
var RADIUS=10;
?
window.onload = function () {
??? var canvas=document.getElementsById('canvas');? ??//調用canvas
??? var context=canvas.getContext("2d");?? //調用繪圖的上下文環(huán)境
?
??? canvas.width=WINDOW_WIDTH;
??? canvas.height=WINDOW_HEIGHT;? //調用全局變量
?
??? render(context)?? //繪圖函數
};
?
function render(cxt) {
??? var hours=12;
??? var minutes=34;
??? var seconds=56;?? //定義時間
?
??? renderDigit(WINDOW_LEFT,WINDOW_TOP,parseInt(hours/10),cxt);? //將數拆開,一個數一個數的繪制
??? renderDigit(WINDOW_LEFT+15*(RADIUS+1),WINDOW_TOP,parseInt(hours%10),cxt);
??? renderDigit(WINDOW_LEFT+30*(RADIUS+1),WINDOW_TOP,10,cxt);
??? renderDigit(WINDOW_LEFT+39*(RADIUS+1),WINDOW_TOP,parseInt(minutes/10),cxt);
??? renderDigit(WINDOW_LEFT+54*(RADIUS+1),WINDOW_TOP,parseInt(minutes%10),cxt);
??? renderDigit(WINDOW_LEFT+69*(RADIUS+1),WINDOW_TOP,10,cxt);
??? renderDigit(WINDOW_LEFT+78*(RADIUS+1),WINDOW_TOP,parseInt(seconds/10),cxt);
??? renderDigit(WINDOW_LEFT+93*(RADIUS+1),WINDOW_TOP,parseInt(seconds%10),cxt);
}
?
function renderDigit(x,y,num,cxt){
??? cxt.fillStyle="rag(0,102,153)";
???
??? for(var i=0;i<digit[num].length;i++)?? //i代表行,j代表列,num代表數,.length代表方法
??????? for(var j=0;j<digit[num][i].length;j++)???? //1是矩陣里的,代表繪制小球
??????? {
??????????? if(digit[num][i][j] == 1) {
?
??????????????? cxt.beginPath();? //繪圖的一個區(qū)間
??????????????? cxt.arc(x + j * 2 * (RADIUS + 1) + (RADIUS + 1), y + i * 2 * (RADIUS + 1) + (RADIUS + 1), RADIUS, 0, 2 * Math.PI);
??????????????? cxt.closePath();
?
??????????????? cxt.fill()
??????????? }
??????? }
}
這有什么錯誤?為什么運行不了?
2017-10-26
不是大神。。復制到本地f12馬上就知道錯誤了。。第7行?document.getElementsById('canvas'); 應該是?document.getElementById('canvas');
學會調試~~