javascript 如何在“pgn[46]"处停止坚韧该数组的迭代?

3phpmpom  于 2023-02-11  发布在  Java
关注(0)|答案(1)|浏览(81)

如何在"pgn [46]"处停止对该数组的迭代?
我希望当我点击按钮时无法转到下一步。因为这个数组将从0开始,如果一个棋子在正方形上,它将再次移动。我需要一些更多的文本在这里发布这个问题。我爱你们所有人,和平

$('#move1Btn').on('click', function () {
  board.move(pgn[intpgnIndex])
})

var pgn = new Array()
pgn[0] = ""
pgn[1] = "e2-e4"
pgn[2] = "e7-e5"
pgn[3] = "f2-f4"
pgn[4] = "e5-f4"
pgn[5] = "f1-c4"
pgn[6] = "d8-h4"
pgn[7] = "e1-f1"
pgn[8] = "b7-b5"
pgn[9] = "c4-b5"
pgn[10] = "g8-f6"
pgn[11] = "g1-f3"
pgn[12] = "h4-h6"
pgn[13] = "d2-d3"
pgn[14] = "f6-h5"
pgn[15] = "f3-h4"
pgn[16] = "h6-g5"
pgn[17] = "h4-f5"
pgn[18] = "c7-c6"
pgn[19] = "g2-g4"
pgn[20] = "h5-f6"
pgn[21] = "h1-g1"
pgn[22] = "c6-b5"
pgn[23] = "h2-h4"
pgn[24] = "g5-g6"
pgn[25] = "h4-h5"
pgn[26] = "g6-g5"
pgn[27] = "d1-f3"
pgn[28] = "f6-g8"
pgn[29] = "c1-f4"
pgn[30] = "g5-f6"
pgn[31] = "b1-c3"
pgn[32] = "f8-c5"
pgn[33] = "c3-d5"
pgn[34] = "f6-b2"
pgn[35] = "f4-d6"
pgn[36] = "c5-g1"
pgn[37] = "e4-e5"
pgn[38] = "b2-a1"
pgn[39] = "f1-e2"
pgn[40] = "b8-a6"
pgn[41] = "f5-g7"
pgn[42] = "e8-d8"
pgn[43] = "f3-f6"
pgn[44] = "g8-f6"
pgn[45] = "d6-e7"
pgn[46] = ""
pgn[47] = ""
pgn[48] = ""
pgn[49] = ""

var intpgnIndex = 0;

function writeThing() {
    if ( intpgnIndex == pgn.length ) intpgnIndex = 0;
    intpgnIndex++;
}
eblbsuwk

eblbsuwk1#

我将检查索引处的值,看看它是否是空字符串:

$('#move1Btn').on('click', function () {
  var move = pgn[intpgnIndex];
  if (move) {
    board.move(move);
  }
})

以下是推荐的方法:
x一个一个一个一个x一个一个二个一个x一个一个三个一个

相关问题