JavaScript implements the method of randomly replacing images


This article illustrates an example of how JavaScript can randomly replace images. Share with you for your reference. The details are as follows:

The following code can be implemented to randomly replace the image on the page with another image, or randomly display 1 image

<script>
document.write(<img src="img/+parseInt(Math.random()*(5))
+.gif"height="40" width="50">
</script>

The image file is called: 0.gif 1.gif 2.gif 3.gif 4.gif

I hope this article has been helpful to your javascript programming.