Use JavaScript to display random images or quot_image Effects

Source: Internet
Author: User
This article will teach you how to create an array of all possible entries with simple JavaScript, and then randomly select the images or references you need to add to the webpage. The first step to use this script is to select the Code in the following text and copy it to the rand. js folder.

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 need to repeat the code () several times as needed until the array includes all the entries you need in the random selection (for example, the starting value of this array is 3, that is to say, if you have 10 entries, you only need to repeat the row seven times ).
If you are using a reference, you just need to replace code (), code1, and code2 with the above text. If you want to use this aunt to display random images, you need to put the HTML code of all the images into the entries. You can create any type of code for your webpage by placing the appropriate HTML and text in the entries, and select randomly.
Finally, use the following code to append the script to the main part of your web page, where you need to display the link or information:
<Script type = "text/javascript" src = "rand. js? 1.1.20 "> </script>
Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.