我有撤銷按鈕的問題我的繪圖應用程序繪圖應用程序撤消按鈕
<input id="undo" type="image" src="images/undo.ico" onclick="cUndo()" width="25" height="25">
var cPushArray = new Array();
var cStep = -1;
var ctx;
// ctx = document.getElementById('myCanvas').getContext("2d");
function cPush() {
cStep++;
if (cStep < cPushArray.length) { cPushArray.length = cStep; }
cPushArray.push(document.getElementById('myCanvas').toDataURL());
}
function cUndo() {
if (cStep > 0) {
cStep--;
var canvasPic = new Image();
canvasPic.src = cPushArray[cStep];
canvasPic.onload = function() { ctx.drawImage(canvasPic, 0, 0); }
}
}
但這並不work.Please幫助
只需在每行/函數前添加註釋,以解釋它在做什麼。一些錯誤應該已經消失。 – GameAlchemist 2014-09-29 14:28:52
如果'ctx'沒有定義,你將無法使用'drawImage'方法 – bencripps 2014-09-29 14:33:15
@GameAlchemist如何添加註釋使錯誤消失? – epascarello 2014-09-29 14:46:41