Home  >  Article  >  Web Front-end  >  How to randomly display background images in javascript_javascript skills

How to randomly display background images in javascript_javascript skills

WBOY
WBOYOriginal
2016-05-16 15:54:131311browse

The example in this article describes the method of randomly displaying background images in javascript. Share it with everyone for your reference. The details are as follows:

Add the following code between the 93f0f5c25f18dab9d176bd4f6de5d30e9c3bca370b5104690d9ef395f2c5f8d1 of the HTML:

<script LANGUAGE="JavaScript">
bg = new Array(2);
//设定图片数量,如果图片数为3,这个参数就设为2,依次类推
bg[0] = 'bg1.gif' //显示的图片路径,可用http://
bg[1] = 'bg2.gif'
bg[2] = 'bg3.gif'
index = Math.floor(Math.random() * bg.length);
document.write("<BODY BACKGROUND="+bg[index]+">");
</script>

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