javascript – 为什么我的for循环在一次迭代后停止?

前端之家收集整理的这篇文章主要介绍了javascript – 为什么我的for循环在一次迭代后停止?前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。

在这个上绞尽脑汁.我有以下代码JavaScript游戏的第一阶段.所有对象都是明确定义的,我正在使用jQuery进行DOM交互.该谜题是使用以下JS代码创建的:

  1. var mypuzzle = new puzzle("{solution:'5+6+89',equations:[['5+3=8',23,23],['5+1=6',150,['5+3=6',230,23]]}");

但是,代码底部的循环不会比第一次迭代更进一步.知道为什么吗?根本没有错误.

  1. function equationBox(equation,top,left) {//draggable equation Box
  2. this.reposition = function() {
  3. this.top = 0;
  4. this.left = 0;
  5. }
  6. this.top = 0;//make random
  7. this.left = 0;//make random
  8. this.equation = equation;
  9. if(top && left) {
  10. this.top = top;
  11. this.left = left;
  12. }
  13. this.content = this.equation.LHS.string + 'Box = function(equationBox) {
  14. $('#puzzle #equations').append(equationBox.DOM);
  15. }
  16. this.init = function() {
  17. //this.drawPuzzleBox();
  18. this.json = JSON.parse(json);
  19. this.solution = new expression(this.json.solution || '');
  20. this.equations = this.json.equations || [];
  21. var iterations = this.equations.length;
  22. for(i=0;iBox(new equationBox(stringToEquation(this.equations[i][0]),this.equations[i][1],this.equations[i][2]));
  23. }
  24. }
  25. this.init();
  26. }
最佳答案
可能你未能对你的计数器变量进行调整,特别是如果你养成它的习惯(因为你正在使用该名称全局变量,并且你在任何代码中编写的任何循环可能都是这样做的)事情).尝试:

  1. for(var i=0;i

猜你在找的JavaScript相关文章