Possible Duplicate:
JavaScript: Getting random value from an array
Could someone help me on this topic? I've got this code.
var textArray = [
'song1.ogg',
'song2.ogg'
]
audioElement.setAttr开发者_如何学JAVAibute('src', textArray);
How can I randomly get one of those strings into my audio element?
Would be glad if someone can help....
var textArray = [
'song1.ogg',
'song2.ogg'
];
var randomNumber = Math.floor(Math.random()*textArray.length);
audioElement.setAttribute('src', textArray[randomNumber]);
var randomIndex = Math.floor(Math.random() * textArray.length);
var randomElement = textArray[randomIndex];
精彩评论