如何让图像在单击按钮时更改
How do I get the image to change when the button is clicked
我很抱歉成为这样的菜鸟,但在编程方面我有很多困难,所以如果有人能帮忙,那就太好了!
基本上,我正在尝试制作一个带有一些图像的zindex,当我单击按钮时,它会切换图像。我知道这可能是非常基本的,但我非常不知道该怎么做。我理解这个概念,但无法输入它。
我也试图让图像位于页面中间。我被推荐给以下人员;但是,这不起作用。有人可以帮忙吗?
这是我所拥有的:
.CSS
#xbone {
position:absolute;
left:0px;
top:0px;
margin-left: auto;
margin-right: auto;
z-index:-1
}
#ps4 {
position:absolute;
left:0px;
top:0px;
margin-left: auto;
margin-right: auto;
z-index:-2
}
#wiiu {
position:absolute;
left:0px;
top:0px;
margin-left: auto;
margin-right: auto;
z-index:-3
}
JavaScript
function changeStackOrder() {
document.getElementById("xbone").style.zIndex="1";
}
.HTML
<img id="xbone" alt="Xbox One" width="800" height="600"
src="http://assets1.ignimgs.com/vid/thumbnails/user/2013/06/19/XboxOne1.jpg">
<img id="ps4" alt="Playstation 4" width="800" height="600"
src="http://www.nowgamer.com/siteimage/scale/0/0/360062.jpg" >
<img id="wiiu" alt="Wii U" width="800" height="600"
src="http://venturebeat.files.wordpress.com/2013/07/wii-u.jpg" >
<input type="button" onclick="changeStackOrder()" value="Change stack order">
小提琴:http://jsfiddle.net/GkGJw/
function changeStackOrder() {
$("img").each(function() {
$(this).css("zIndex", "+=1");
if($(this).css("zIndex") == "0"){
$(this).css("zIndex", "-3");
}
});
}
尝试这样的事情
它没有改变,因为将 xbone 的 zIndex 设置为 1 仍然会让它在顶部。如果您为任何其他图像执行此操作,它将出现在顶部。
相关文章:
- 如何隐藏按钮单击事件上的占位符
- 从Web服务器下载图像按钮单击使用JavaScript
- 在SweetAlert中传递ASP.NET按钮单击事件
- 单选按钮单击可刷新/更改网站的小区域
- 调用按钮单击事件 ajax 加载的用户控件
- 附加 jQuery 代码以在加载和按钮单击时运行
- 在按钮单击时将图像URL数据显示到弹出框中,而无需禁用背景
- 按钮单击服务器单击
- 触发单选按钮单击,并在页面刷新时记住选择
- 如何使用 javascript 而不是使用控制器中的方法在 rails 中呈现部分按钮单击
- jQuery UI 选项卡 - 将参数设置为下一个/上一个按钮单击
- 如何在 Angular JS 中的按钮单击上添加类
- 当元素上有多个类时触发按钮单击事件
- 如何在 HTML 中的按钮单击上更改图像(IMG URL 每次来自服务器)
- 如何使用javascript刷新我的html页面时清除按钮单击
- 阻止后退按钮 - 单击按钮时忽略
- 如何制作按钮.单击“开始时不运行”
- Rails:尝试在按钮单击时渲染部分
- 在页面加载时调用函数,在按钮单击时再次调用函数,但参数不同
- 如何在服务器端的文本中添加按钮单击事件