Js random array string (random advertisement)

Source: Internet
Author: User

On a large portal website, we will see that the ads displayed for the first time are different. Next I will introduce you to the random array strings. In fact, the ads are almost random.

Instance

The Code is as follows: Copy code

<Script language = "JavaScript" type = "text/JavaScript">
TheAds = new Array ();
Shu = 13;
Dot = '';
TheAds [1] = 'www. bKjia. c0m 1st ';
TheAds [2] = 'www. bKjia. c0m 2's ';
TheAds [3] = 'www. bKjia. c0m Article 3 ';
TheAds [4] = 'www. bKjia. c0m 4 ';
TheAds [5] = 'www. bKjia. c0m Article 5 ';
TheAds [6] = 'www. bKjia. c0m Article 6 ';
TheAds [7] = 'www. bKjia. c0m article 7 ';
TheAds [8] = 'www. bKjia. c0m article 8 ';
TheAds [9] = 'www. bKjia. c0m 9 ';
TheAds [10] = 'www. bKjia. c0m Article 10 ';
TheAds [11] = 'www. bKjia. c0m 11th ';
TheAds [12] = 'www. bKjia. c0m 12th ';
TheAds [13] = 'www. bKjia. c0m 13th ';
Adshu = shu + 1
Function Quickpick ()
{
Var ball
For (ball = 1; ball <adshu; ball ++)
{
This [ball] = parseInt (Math. random () * shu + 1 );
For (var list = 0; list <ball; list ++)
{
If (this [list] = this [ball])
{
List = ball;
Ball --;
}
}
}
Return this;
}
Var idx;
Var ballball = new Array (shu );
Ballball = this. Quickpick ();
For (idx = 1; idx <adshu; idx ++ ){
Document. write (dot + theAds [ballball [idx] + '<br> ');
If (idx <shu) {document. write ('')}}
// Document. write (dot + theAds2 );
</Script>

A random array sorting Function

The Code is as follows: Copy code

Var wangwangList = ['Consult online', 'Consult online1', 'Consult online2', 'Consult online3'];

/**
* Random Prepayment
* @ Param trademanager Name List
* @ Returns HTML code
**/
Function randomWangWang (){
Var B, C;
Var X = [];
Var j = 0;
For (I = A. length; I> = 1; I --){
C = Math. floor (Math. random () * A. length );
X [j] = outWangWangCode (A [C]);
A. splice (C, 1)
J ++;
}
Return X
}

/**
* Convert to HTML link form
* @ Param trademanager name
* @ Returns HTML code
**/
Function outWangWangCode (n ){
Var _ n = encodeURIComponent (n );
Var html = '';
Html + ='
<LI> <A class = img title = click here to send me A message href = "http://amos.im.alisoft.com/msg.aw? V = 2 & uid = '+ _ n +' & site = cntaobao & s = 1 & charset = UTF-8 "target = _ blank> ';
Html + = ' </A> '+ n +' </LI>

';
Return html;
}

/**
* Transfer out all lists
* @ Param write mode or return Mode
* @ Returns HTML code
**/
Function writeWangWangHTML (write ){
Var html ='
<UL> ';
Var x = randomWangWang (wangwangList );
For (I in x ){
Html + = x [I];
}
Html + = '</UL>

';
Return html;
}

// Display code
Document. write (writeWangWangHTML ());

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.