Home  >  Article  >  Web Front-end  >  How to implement random display of advertisements on Javascript static pages_javascript skills

How to implement random display of advertisements on Javascript static pages_javascript skills

WBOY
WBOYOriginal
2016-05-16 18:16:211440browse

First, to generate non-repeating random numbers within n and put the generated random numbers into another Array, use the following method to complete:

Copy code The code is as follows:

function getRandomNumbers(count)
{
var numbers = new Array();
var original = new Array() ;
for (var i=0;i{
original[i] = i 1;
}
original.sort(function(){ return 0.5 - Math.random(); });
for (var i=0;i{
numbers[i] = original[i] - 1;
}
return numbers;
}

Then, in the background program, output the html script:
Copy code The code is as follows:

var sf = new Array();
sf[0]='Server nameServer IPOpening timeLine categoryVersion introductionCustomer Service QQDetailed Introduction< /TD>';
sf[1]='Server nameServer IPOpening Time< /TD>Line CategoryVersion IntroductionCustomer Service QQDetails';

Use the previous method to generate random numbers and display the html script according to the random numbers.
Copy code The code is as follows:

var numbers = getRandomNumbers(sf.length);
for( i=0;i{
document.write(sf[numbers[i]]);
}
Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn