使用jQuery点击按钮下载图片 [英] Download image on button click using jQuery

查看:91
本文介绍了使用jQuery点击按钮下载图片的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的网页上有一张图片。我想要单击按钮时下载图像。我如何使用jQuery或Javascript做到这一点?请给我一个小提琴。 FIDDLE

I have an image in my page. I want the image to be downloaded when I click on a button. How can I do this using jQuery or Javascript? Kindly provide me with a fiddle. FIDDLE

<div id="download">
    <img src="http://www.glamquotes.com/wp-content/uploads/2011/11/smile.jpg" id="image">
    <button id="dwnld"> Download image </button>
</div>


推荐答案

您可以使用HTML5 download 属性,如果以前的浏览器是个问题,你应该使用serverside来设置它,然后设置适当的头文件等。

You can actually do this with the HTML5 download attribute, if older browsers are an issue, you should use the serverside for this, and set the appropriate headers etc.

<a href="http://www.glamquotes.com/wp-content/uploads/2011/11/smile.jpg" download="smile.jpg">Download image</a>

FIDDLE

这篇关于使用jQuery点击按钮下载图片的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆