Try this function
function getRandomImage(imgAr, path) {
path = path || 'images/'; // default path here
var num = Math.floor( Math.random() * imgAr.length );
var img = imgAr[ num ];
var imgStr = '<img src="' + path + img + '" alt = "">';
document.write(imgStr); document.close();
}
Call the function
getRandomImage(ARRAY-VARIABLE, '/images/')
Refer LIVE DEMO. You will see change in image for every refresh
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…