Current location - Plastic Surgery and Aesthetics Network - Plastic surgery and medical aesthetics - What is the code of the web banner?
What is the code of the web banner?
This is a special effect of JAVAsrcipt: random display of pictures is a very widely used skill.

For example, the display of random banner, when you enter a website, its banner is always different, or there are always different content prompts. You will often find such examples when you browse online.

In fact, as long as you have a little foundation in html and javascript, everything is so simple.

Usually we will add pictures to the page to complete it.

If we want to display three different pictures randomly, we need to make a small modification to this code, first add

Put the type of write ("") in and it becomes a document.

Write ("& ltImgsrc= picture >" Now let's finish the most important part: id=Math.

Circle (mathematics

Random()*2)+ 1 The random number thus obtained is 1, 2, 3. Rename the picture to be displayed to 1.

gif,2

gif,3

gif,ok! The final code is:

Circle (mathematics

Random()* 2)+ 1 document

Write ("& ltimgsrc="+id+"

gif & gt”)& lt/script & gt; Try it, won't you? What if each of my pictures corresponds to a hyperlink? Let's assume that there are three pictures, 1.

gif,2

gif,3

Gif, the corresponding link is url 1, url2, url3.

In order to make pictures correspond to links one by one, we need to set an array image to place the addresses of links, as follows: varimage=newArray(3)image.

Length = 3 image [1] = "URL1"image [2] = "url2" image [3] = "url3" In order to take out the links corresponding to the images, we also need to define an array imageurl=image[id]. The principle is as follows: when reading the page, take a random number and assume.

Display of gif on the page

Then we can see: imageurl=image[2] and image[2]="url2 ",and the rest will be easy.

The complete code is as follows:

length = 3 image[ 1]= " URL 1 " image[2]= " URL 2 " image[3]= " URL 3 " id = Math

Circle (mathematics

random()* 2)+ 1 imageurl = image[id]document

Write ("<a href ="+banner URL+">+"< imgsrc="+id+"

gif & gt”)& lt/script & gt;