我尝试使用一个空数组,该数组在单击图像时填充,将图像ID发送到findMatch()
函数,该函数又用于在isMatch()
函数中插入匹配项。我的isMatch()
函数无法正常工作。我已经尝试在Chrome中调试,但这无济于事。任何帮助或建议,将不胜感激。选择2张图像后,我需要清除阵列。
function isMatch() {
if ((count === 1) && (pic == 1)) {
cMatch.unshift(arrMatch);
match1 = imgID;
}
if ((count === 2) && (pic == 1)) {
// var index2=declick(clicked);
cMatch.push(arrMatch);
match2 = imgID; {
if (cMatch[0] === cMatch[1]) {
bMatch = true;
cMatch.length = 0;
cMatch = [];
count = 0;
match1 = 0;
match2 = 0;
} else {
bMatch = false;
document.getElementById(match1).src = defaultImage;
document.getElementById(match2).src = defaultImage;
cMatch.length = 0;
cMatch = [];
count = 0;
match1 = 0;
match2 = 0;
}
//else{bMatch=false;}}
}
if (count > 2) {
document.getElementById(match1).src = defaultImage;
document.getElementById(match2).src = defaultImage;
count = 0;
return bMatch;
}
}
}
进入Chrome浏览器时,该代码似乎可以正常工作,但是当我在浏览器中使用该代码时,它根本无法工作。