Home >Web Front-end >JS Tutorial >JavaScript method to randomly replace images_javascript skills

JavaScript method to randomly replace images_javascript skills

WBOY
WBOYOriginal
2016-05-16 16:03:341231browse

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.

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn