JS implement array random string (ad random)

Source: Internet
Author: User

Instance

The code is as follows Copy Code

<script language= "JavaScript" type= "Text/javascript" >
Theads=new Array ();
Shu = 13;
Dot= ';
theads[1]= ' www.111cn.net first ';
Theads[2]= ' www.111cn.net second ';
Theads[3]= ' www.111cn.net third ';
Theads[4]= ' www.111cn.net fourth ';
Theads[5]= ' www.111cn.net fifth ';
Theads[6]= ' www.111cn.net sixth ';
theads[7]= ' www.111cn.net seventh ';
Theads[8]= ' www.111cn.net eighth ';
theads[9]= ' www.111cn.net nineth ';
Theads[10]= ' www.111cn.net tenth ';
theads[11]= ' www.111cn.net 11th ';
theads[12]= ' www.111cn.net 12th ';
theads[13]= ' www.111cn.net 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>

Look at an array of random sort functions

The code is as follows Copy Code

var wangwanglist = [' Consulting online ', ' consulting online1 ', ' consulting Online2 ', ' consulting online3 '];

   /**
     * Random pre
     * @param Wang Wang Name list
 & nbsp;   * @returns HTML code
     **/
    function Randomwangwang (A) {
        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 Wang Wang 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;
}

/**
* Go out full list
* @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 ());

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.