div.numDiv{ 너비 : 100% ; 높이: 100% ; 배경색 : #000 ; 색상 : #FFF ; 텍스트 정렬: 가운데 ; 수직 정렬 : 중간 ; }
<스크립트> var currPos = 9; 함수 이동(이벤트){ 스위치(event.keyCode){ case 37 : // 左键 if (currPos % 3 != 0){ var currTd = document.getElementById("numTd_" currPos); var nextTd = document.getElementById("numTd_" (currPos 1)); var temp = nextTd.innerHTML; nextTd.innerHTML = " "; currTd.innerHTML = 임시; currPos ; } 휴식; case 38: // 上键 if (currPos < 7){ var currTd = document.getElementById("numTd_" currPos); var nextTd = document.getElementById("numTd_" (currPos 3)); var temp = nextTd.innerHTML; nextTd.innerHTML = " "; currTd.innerHTML = 임시; currPos = 3; } 휴식; case 39: // 右键 if (currPos % 3 != 1){ var currTd = document.getElementById("numTd_" currPos); var nextTd = document.getElementById("numTd_" (currPos - 1)); var temp = nextTd.innerHTML; nextTd.innerHTML = " "; currTd.innerHTML = 임시; currPos -- ; } 휴식; case 40: // 下键 if (currPos > 3){ var currTd = document.getElementById("numTd_" currPos); var nextTd = document.getElementById("numTd_" (currPos - 3)); var temp = nextTd.innerHTML; nextTd.innerHTML = " "; currTd.innerHTML = 임시; currPos -= 3; } 휴식; 기본값: break; }
if (isWin()){ alert("恭喜你,过关了!"); initNums(); }
}
function isWin(){ for (i = 1; i < 9; i ){ var numTd = document.getElementById(" numTd_" i); var numDiv = numTd.getElementsByTagName("div"); if (i != numTd.innerText){ false를 반환합니다. } } true를 반환합니다.
}
function initNums(){ var numArr = new Array(1, 2, 3, 4, 5, 6, 7, 8, 9); var newnewNumArr = new Array();