这是我正在尝试开发的益智游戏的片段。问题是它在调用 jquery 的 each()
后停止工作。请帮我找出问题所在。提前致谢。
function setTotalInPositionPieces()
{
$("#board").children('div').each(function(index, element) {
if(testInPosition(element))
{
++totalInPositionPieces;
$(element).attr("data-inPositionStatus", '1');
}
});
/* The script does not from here, onward. Please tell
me what is the problem.*/
if(totalInPositionPieces == totalPieces)
{
$("#messageBox").text("Puzzle Solved!");
}
}
totalInPositionPieces
和 totalPieces
是全局变量。
最佳答案
您应该将 each
函数外部的 var totalInPositionPieces
定义为可在任何其他函数范围内或外部访问。
totalPieces
也是如此。你在哪里定义它?
关于javascript - 脚本未运行 jquery .each,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14446831/