我如何实现下载按钮?

时间:2017-05-27 19:54:31

标签: javascript html css image download

在我的网站索引上,我目前正在显示18张随机图片,这是我目前用来显示这些图片的代码:

这是我想要在以下网站上实现此功能的网站: http://www.freevatars.co.uk

HTML:

<script type="text/javascript">
document.write(getImageTag());
</script>

JS:

var imageURLs = [
"css/images/avatars/1.png"
 , "css/images/avatars/2.jpg"
 , "css/images/avatars/3.png"
 , "css/images/avatars/4.png"
 , "css/images/avatars/5.png"
 , "css/images/avatars/6.png"
 , "css/images/avatars/7.png" 
 , "css/images/avatars/8.jpg"
 , "css/images/avatars/9.jpg"
 , "css/images/avatars/10.png"
 , "css/images/avatars/11.jpg"
 , "css/images/avatars/12.jpg"
 , "css/images/avatars/13.jpg"
 , "css/images/avatars/14.png"
 , "css/images/avatars/15.jpg"
 , "css/images/avatars/16.png"
 , "css/images/avatars/17.jpg"
 , "css/images/avatars/18.jpg"
 ];
 function getImageTag() {
var img = '<img src=\"';
var randomIndex = Math.floor(Math.random() * imageURLs.length);
img += imageURLs[randomIndex];
img += '\" alt=\"Oh no, the image is broken!\"/>';
return img;
}
// Images in JS code go up to 410, so I have only placed 18 here to shorten it.

我希望在悬停上实现下载按钮或类似系统,但是,随着JS随机显示图像,我无法使用标准HTML ahref下载代码,因为我需要一个绝对路径到图像。

有人知道如何实现这一点并保留随机图像吗?

提前致谢!

0 个答案:

没有答案