我想用链接制作随机图像,但我不明白。有人可以帮帮我吗?
这是标题中的javascript
<script type="text/javascript">
var random_images_array = ['banner/headline/chrome.png','banner/headline/thunderbird.png','banner/headline/vlc.png'];
function getRandomImage(imgAr, path) {
path = path || 'images/';
var num = Math.floor( Math.random() * imgAr.length );
var img = imgAr[ num ];
var lnk = imgAr[ num ];
var imgStr = '<img src="' + path + img + '" alt="" class="img-responsive">';
document.write(imgStr); document.close();
}
</script>
这是正文中的javascript
<script type="text/javascript">
getRandomImage(random_images_array, 'images/')
</script>