2010-07-21 30 views
1

我想在javascript中構建圖像翻轉 有2個按鈕和1個圖像 當用戶按下按鈕數字1時按鈕的顏色發生變化,而第二個按鈕保持不變並且圖片更改和超鏈接改變也 當我壓按鈕2按鈕的顏色變化和顏色的按鈕1回到原來的顏色和圖像的變化,也超鏈接Javascript圖像滾過

請我需要幫助,如果有人可以幫助我,我需要它作爲一個Java腳本

回答

0
<div id=Image1><a href="url1"><img src=image1.jpg></a></div> 
<div id=Image2 style="visibility: hidden; position: absolute; left: -1000px; top: -1000px;"><a href="url2"><img src=image2.jpg></a></div> 

<input type=button id=Button1 onclick="JavaScript: changeImage(1);"> 
<input type=button id=Button2 style="background-color: red;" onclick="JavaScript: changeImage(2);"> 

<script language="JavaScript"> 
    function changeImage(n) 
    { 
    var div1 = document.getElementById("Image1"); 
    var div2 = document.getElementById("Image1"); 

    var btn1 = document.getElementById("Button1"); 
    var btn2 = document.getElementById("Button2"); 

    if(n == 1) 
    { 
     div1.style.visibility = "visible"; 
     div1.style.position = "relative"; 
     div1.style.top = div1.style.left = ""; 

     div2.style.visibility = "hidden"; 
     div2.style.position = "absolute"; 
     div2.style.top = div1.style.left = "-1000px"; 

     btn1.style.backgroundColor = ""; 
     btn2.style.backgroundColor = "red"; 
    } 
    else 
    { 
     div1.style.visibility = "hidden"; 
     div1.style.position = "absolute"; 
     div1.style.top = div1.style.left = "-1000px"; 

     div2.style.visibility = "visible"; 
     div2.style.position = "relative"; 
     div2.style.top = div1.style.left = ""; 

     btn1.style.backgroundColor = "red"; 
     btn2.style.backgroundColor = ""; 
    } 
    } 
</script>