我正在尝试在javascript中构建图像滚动 有2个按钮和1张照片 当用户按下按钮编号1时,按钮的颜色改变,并且第二个按钮保持不变,图片改变,并且它的超链接也改变 当我按下按钮2时,按钮的颜色改变,按钮1的颜色返回原始颜色,图像改变,也有超链接
如果有人能帮助我,我需要帮助,我需要它作为一个java脚本
答案 0 :(得分: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>