2010-05-24 6 views
0

아래 코드는 사용자가 1 개 개체 위로 마우스를 가져갈 수 있으며 개체를 대체 할뿐만 아니라 버튼 사이에 추가 개체를 표시합니다.여러 이미지를 생성하는 마우스 오버가 Firefox에서 작동하지만, 그렇지 않은 경우

Firefox에서는 잘 작동하지만 Internet Explorer에서는 작동하지 않습니다.

HELP

웹 페이지 : http://www.isp.ucar.edu/

들으, 테리 모든

if (< document.images) { 

    img1on = new Image(); 
    img1on.src = "images/buttons/button-beachon-on.gif"; 
    img1off = new Image(); 
    img1off.src = "images/buttons/button-beachon.gif"; 

    img2on = new Image(); 
    img2on.src = "images/buttons/button-bgs-on.gif"; 
    img2off = new Image(); 
    img2off.src = "images/buttons/button-bgs.gif"; 

    img3on = new Image(); 
    img3on.src = "images/buttons/button-iam-on.gif"; 
    img3off = new Image(); 
    img3off.src = "images/buttons/button-iam.gif"; 

    img4on = new Image(); 
    img4on.src = "images/buttons/button-nvia-on.gif"; 
    img4off = new Image(); 
    img4off.src = "images/buttons/button-nvia.gif"; 

    img5on = new Image(); 
    img5on.src = "images/buttons/button-utls-on.gif"; 
    img5off = new Image(); 
    img5off.src = "images/buttons/button-utls.gif"; 

    img6on = new Image(); 
    img6on.src = "images/buttons/button-water-on.gif"; 
    img6off = new Image(); 
    img6off.src = "images/buttons/button-water.gif"; 

    img7on = new Image(); 
    img7on.src = "images/buttons/button-exploratory-on.gif"; 
    img7off = new Image(); 
    img7off.src = "images/buttons/button-exploratory.gif"; 


    // second image that does not appear in original button space 
    img1ad = new Image(); 
    img1ad.src = "images/buttons/beachon-overview-sm.gif"; 

    img2ad = new Image(); 
    img2ad.src = "images/buttons/bgs-overview-sm.gif"; 

    img3ad = new Image(); 
    img3ad.src = "images/buttons/iam-overview-sm.gif"; 

    img4ad = new Image(); 
    img4ad.src = "images/buttons/nvia-overview-sm.gif"; 

    img5ad = new Image(); 
    img5ad.src = "images/buttons/utls-overview-sm.gif"; 

    img6ad = new Image(); 
    img6ad.src = "images/buttons/water-overview-sm.gif"; 

    img7ad = new Image(); 
    img7ad.src = "images/buttons/exploratory-overview-sm.gif"; 
} 

function imgOn(imgName) { 
    if (document.images) { 
     document[imgName].src = eval(imgName + "on.src"); 
     document["holder"].src = eval(imgName + "ad.src"); 
    } 
} 

function imgOff(imgName) { 
    if (document.images) { 
     document[imgName].src = eval(imgName + "off.src"); 
     document["holder"].src = "images/buttons/isp-overview-sm.gif"; 
    } 
} 
+0

의도적 인 'ocuments.images'에 'd'가 누락 되었습니까? 또한 코드 등을 게시하는 방법에 대한 FAQ를 읽으십시오. –

답변

0

첫째, 이러한 기능에 eval 그들은 쉬

function imgOn(imgName) { 
    if (< document.images) { 
     document[imgName].src = eval(imgName + "on.src"); 
     document["holder"].src = eval(imgName + "ad.src"); 
    } 
} 

function imgOff(imgName) { 
    if (< document.images) { 
     document[imgName].src = eval(imgName + "off.src"); 
     document["holder"].src = "images/buttons/isp-overview-sm.gif"; 
    } 
} 

에 완전히 지껄이다 울드는

function imgOn(imgName) { 
    document.getElementById(imgName).src = window[imgName + "on"].src; 
    document.getElementById("holder").src = window[imgName + "ad"].src; 
} 

function imgOff(imgName) { 
    document.getELementById(imgName).src = window[imgName + "off"].src; 
    document.getElementById("holder").src = "images/buttons/isp-overview-sm.gif"; 
} 

을 읽고 대신 window[foo] 호출 다음에 여러 img1on = new Image(); 당신이이

var myImages = {}; 
myImages["img1on" = new Image(); 

그런 다음 나중에

var foo = myImages[imgName + "on"].src; 

src을 얻기 위해 할 수있는해야한다.

+0

위의 내용은 처음로드되었을 때 이미지가 표시되지만 롤오버하면 "on"및 "ad"이미지를 찾을 수 없으며 항목을 벗어난 후에도 이미지가 표시됩니다. 원본 이미지가 다시 나타나지 않습니다 (처음에는 실제로 제 문제였습니다). 다른 아이디어가 있습니까? 정말 고마워요. Terri – tcantrel

+0

테스트 : isp.ucar.edu/index3.php – tcantrel

+0

약간의 수정을 시도 : 롤오버는 작동하지만 원래 이미지로 돌아 가지 않습니다. function imgOn (imgName) { document.getElementById (imgName) .src = eval (imgName + "on.src"); document.getElementById ("holder"). src = eval (imgName + "ad.src"); } function imgOff (imgName) { document.getELementById (imgName) .src = imgName + "off.src"; document.getElementById ("holder"). src = "images/buttons/isp-overview-sm.gif"; } isp.ucar.edu/index4.php – tcantrel

관련 문제