javascript method of randomly displaying background images

  • 2020-06-19 09:37:15
  • OfStack

This article illustrates javascript's method of randomly displaying background images. Share to everybody for everybody reference. The details are as follows:

Add the following code to HTML's < head > < /head > Between:

<script LANGUAGE="JavaScript">
bg = new Array(2);
// Set the number of images, if the number of images is 3 And this parameter is set to 2 , and so on 
bg[0] = 'bg1.gif' // The image path displayed is available http://
bg[1] = 'bg2.gif'
bg[2] = 'bg3.gif'
index = Math.floor(Math.random() * bg.length);
document.write("<BODY BACKGROUND="+bg[index]+">");

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

Related articles: