把我的大腦絞在這一塊上。我有下面的代碼:JavaScript遊戲的第一階段。所有對象都定義良好,我使用jQuery進行DOM交互。拼圖是用以下JS代碼創建的:爲什麼我的for循環在一次迭代後停止?
var mypuzzle = new puzzle("{solution:'5+6+89',equations:[['5+3=8',23,23],['5+1=6',150,23],['5+3=6',230,23]]}");
但是,代碼底部的循環不會比第一次迭代更進一步。任何想法爲什麼?根本沒有錯誤發生。
function equationBox(equation, top, left) {//draggable equation box
this.reposition = function() {
this.top = 0;
this.left = 0;
}
this.top = 0;//make random
this.left = 0;//make random
this.equation = equation;
if(top && left) {
this.top = top;
this.left = left;
}
this.content = this.equation.LHS.string + '<span> = </span>' + this.equation.RHS.string;
this.DOM = $('<li>').html(this.content);
}
function puzzle(json) {
this.addEquationBox = function(equationBox) {
$('#puzzle #equations').append(equationBox.DOM);
}
this.init = function() {
//this.drawPuzzleBox();
this.json = JSON.parse(json);
this.solution = new expression(this.json.solution || '');
this.equations = this.json.equations || [];
var iterations = this.equations.length;
for(i=0;i<iterations;i++)
{
console.log(i);
this.addEquationBox(new equationBox(stringToEquation(this.equations[i][0]),this.equations[i][1], this.equations[i][2]));
}
}
this.init();
}
什麼是「迭代」設置? – ChrisF 2009-08-27 13:18:16
定義了「JSON.parse」在哪裏? – 2009-08-27 13:32:34
當你調試這個時會發生什麼? – Charlie 2009-08-27 13:32:57