Home >Web Front-end >JS Tutorial >JavaScript method to randomly replace images_javascript skills
The example in this article describes the method of randomly replacing images in JavaScript. Share it with everyone for your reference. The details are as follows:
The following code can randomly replace the pictures on the page with other pictures, or randomly display a picture
<script> document.write(<img src="img/+parseInt(Math.random()*(5)) +.gif"height="40" width="50"> </script>
The image file names are: 0.gif 1.gif 2.gif 3.gif 4.gif
I hope this article will be helpful to everyone’s JavaScript programming design.