我有一個畫面是在事件的onload設置:問題得到元素
function hideMe() {
document.getElementById("navy1").style.display = "none";
}
和我還有一個功能設置屏幕上的畫面:
function setUpPicture() {
subRunnerOBJ = new Object();
subRunnerOBJ.topPos = 100;
subRunnerOBJ.leftPos = 0;
subRunnerOBJ.velX = 400;
subRunnerOBJ.velY = 0;
subRunnerOBJ.score = 0;
snImgObj = document.getElementById("navy1");
//在這一點上即時得到的問題「Microsoft JScript運行時錯誤:無法獲取屬性的值'style':object is null or undefined」
snImgObj.style.left = subRunnerOBJ.leftPos + "px";
snImgObj.style.top = subRunnerOBJ.topPos + "px";
snImgObj.style.position = "absolute";
snImgObj.style.display = "show";
startMovePicture();
任何想法爲什麼這個happan?
//this one will set the the pictue on the right side of the screen
function setUpPicture() {
subRunnerOBJ = new Object();
subRunnerOBJ.topPos = 100;
subRunnerOBJ.leftPos = 0;
subRunnerOBJ.velX = 400;
subRunnerOBJ.velY = 0;
subRunnerOBJ.score = 0;
//document.getElementById("navy1").style.display = "show";
snImgObj = document.getElementById("navy1");
snImgObj.style.left = subRunnerOBJ.leftPos + "px";
snImgObj.style.top = subRunnerOBJ.topPos + "px";
snImgObj.style.position = "absolute";
snImgObj.style.display = "show";
//once we place the location of the sub , we will Call to new function that will move it
startMovePicture();
}
function startMovePicture() {
dt = 50; // in miliseconds
h = setInterval("moveObj(subRunnerOBJ)", dt);
}
function moveObj(someObj) {
counter = 0;
while (counter < 3000) {
subRunnerOBJ.leftPos = subRunnerOBJ.leftPos + subRunnerOBJ.velX * dt/1000;
subRunnerOBJ.topPos = subRunnerOBJ.topPos + subRunnerOBJ.velY * dt/1000;
snImgObj.style.left = subRunnerOBJ.leftPos + "px";
snImgObj.style.top = subRunnerOBJ.topPos + "px";
counter = counter + 50;
if (counter == 3000) {
stopRunning()
}
}
}
function stopRunning() {
clearInterval(h);
hideMe();
}
//this function will hide the pucture on liad , and once the loop with the Pictue Running will end
//once loading the page we will not see the Picture
function hideMe() {
document.getElementById("navy1").style.display = "none";
}
}
is this [tag:java] or [tag:javascript]? – secretformula
向我們展示完整的代碼,在這裏是不可能的。 – gdoron
檢查完整的代碼 –