Home > Web Front-end > JS Tutorial > body text

Display random images or quotes with JavaScript_Image effects

WBOY
Release: 2016-05-16 18:53:59
Original
977 people have browsed it

The first step in using this script is to select the code in the text below and copy it to the rand.js folder.

Copy code The code is as follows:

var mess = new Array('code0','code1 ','code2');
var max = mess.length;
var num = Math.floor((Math.random() * max));
document.writeln(mess[num]) ;

Now you need to update this code to specify the image or reference you need. First, you repeat the code() line as many times as needed until the array contains all the entries you need in the random selection (example: its starting value is 3, which means if you have 10 entries, Then just repeat the line 7 times).
If you are using references, you just need to simply replace code(), code1, code2 with the text above. If you want to use this to display random images, then you need to put the HTML code for all images into the entry. You can create any type of code for your web page by placing the appropriate HTML and text into the entry, again chosen randomly.
Finally, use the following code to attach the script to the main part of your web page, where you need to display links or information:
< script type="text/javascript" src="rand.js"> < /script>
Related labels:
source:php.cn
Statement of this Website
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!