tigra
Administrator
Posts: 1920
Registered: 6/17/2002
Location: US, CO
Member Is Offline
|
| posted on 7/11/2005 at 06:35 PM |
|
|
show random fragments of the HTML code
/* list all items */
var a_items = [
'<img src="images/1.gif">',
'<img src="images/2.gif">',
'<img src="images/3.gif">',
'<img src="images/4.gif">',
'<img src="images/5.gif">',
'<img src="images/6.gif">',
'<img src="images/7.gif">',
'<img src="images/8.gif">'
];
function randomize (a_items, n_count) {
var n_index, s_html = '<table cellpadding="0" cellspacing="1" border="0"><tr>';
while (a_items.length && n_count) {
n_index = Math.ceil(Math.random() * a_items.length) - 1;
s_html += '<td>' + a_items[n_index] + '</td>';
a_items[n_index] = a_items[a_items.length - 1];
a_items.length = a_items.length - 1;
n_count--;
}
return s_html + '</tr></table>';
}
// call randomizer
// param 1 - list of items
// param 2 - number of items to display
document.write(randomize (a_items, 3));
Attachment: randomizer.zip (5.15kb)
This file has been downloaded 720 times
|
|
|
|