简体   繁体   English

在php页面中使用javascript更改按钮单击图像

[英]change images on button click using javascript in php page

I have stored all images in a folder. 我已将所有图像存储在一个文件夹中。 and added an image in div and button "Next" in my php page, but now i am writing javascript to change the image on click of button "Next". 并在我的php页面中添加div和按钮“Next”中的图像,但现在我正在编写javascript来更改单击按钮“Next”时的图像。 Please tell me how can i do so? 请告诉我我该怎么办?

I think the best way to do it is storing images urls in js array, then on click event changing the src attribute of Your img container(by reading next array item) which is supposed to display images. 我认为最好的方法是将图像url存储在js数组中,然后在click事件中更改你的img容器的src属性(通过读取下一个数组项)来显示图像。 This is it, You can also use onload event and show some loader while browser would be downloading image from server. 就是这样,您也可以使用onload事件并显示一些加载器,而浏览器将从服务器下载图像。

Consider your html like 考虑一下你的html

...

<div id="img-div">

<img ...../>

</div>

....

And you need to make an ajax call that sends a number or name of the next image to be taken. 并且您需要进行ajax调用,以发送要拍摄的下一个图像的数字或名称。

The php page corresponding to the ajax call need to echo the the tag with the new image in it. 对应于ajax调用的php页面需要使用新图像回显标记。

And then you need to replace the contents using .html() or .innerHTML with js. 然后你需要使用.html()或.innerHTML和js替换内容。

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

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