简体   繁体   English

如何使用一个按钮的Javascript在两个图像之间切换

[英]How To Toggle Between Two Images With One Button Javascript

In my code I have a background on my body. 在我的代码中,我的身体有背景。 The picture change into another one bothering on when it's night or day. 不论白天还是黑夜,图片都会变成另一张。 But I need to have a "fast forward button" that change the theme/background even though it's not the right time of day. 但是我需要有一个“快进按钮”来更改主题/背景,即使不是正确的时间。

Basically I need to be able to toggle between the two pictures with the press of a button. 基本上,我需要能够通过按下按钮在两张图片之间切换。

You can see an example of how I would do it here: http://www.codeply.com/go/MvmYtciu10 您可以在此处查看如何执行此操作的示例: http : //www.codeply.com/go/MvmYtciu10

With regards, John 问候,约翰

Easy enough. 很简单。

Define an event to the click of the button on your client code. 单击客户端代码上的按钮,定义一个事件。

When the event fires, change the src attribute of your image element depending on it's current value. 事件触发时,根据图像元素的当前值更改其src属性。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM