话不多说 上代码
count = 0;
function chg(item){
count ++;
if(count>=100){
countNum = count-100;
console.log(countNum);
document.getElementById("count").innerText=countNum;
}
var id=item.id-0;
var white =document.getElementsByName("white");
var source;
var wh=white[0];
var name =item.name;
var wId=white[0].id-0;
var wName=white[0].name;
if( id+1==wId||id-1==wId||id+3==wId||id-3==wId){
source="./"+name+".jpg";
var w=white[0].name;
whiteSrc="./"+w+".jpg";
item.src=whiteSrc;
wh.src=source;
document.getElementById(wh.id).name=name;
item.name=wName;
item.setAttribute("id",wId);
white[0].setAttribute("id",id);
}
var win =function(){
if(count > 100){
for(i=0;i<9;i++){
var ids = i + "";
if( document.getElementById(ids).name == ids || (i==5&&document.getElementById(ids).name == "white")){
window.alert("win!!");
}
}
}
}
win();
}
调用函数后会报错,提示win()未声明,求解答为什么会报错。