JavaScript Instance Tutorial (10) randomly displaying pictures

Source: Internet
Author: User
Javascript| Tutorials | random | show
Use JavaScript to randomly display pictures

Sometimes you can see some of the changes displayed on some websites, except that you can use Flash to make Of course, you can also use this section of the tutorial introduced the method to achieve OH. All right, let's start with our creations. We can add the following code in the front of the page to create a random number:

<script>

<!--

//randomizer

Rnd.today=new Date ( );

Rnd.seed=rnd.today.gettime ();


Function rnd () {

Rnd.seed = (rnd.seed*9301+49297)% 233280;

Return rnd.seed/(233280.0);

};

Function rand (number) {

return Math.ceil (Rnd () *number);

};


//End Randomizer

</script>

To create a random number from 1 to 10, you can rand (7). To display a random display from num1.gif to Num7.gif, you can write the following code to your Web page:

<script language= "javascript" ><!--

document.write ('

width= ' height= ' > ');

!----> file://--></ script>

All OK, you can enjoy your masterpiece. Until now you may have a bit more experience with javascript: The JavaScript feature is so powerful. I think this is largely due to the many functional functions that JavaScript has.



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.