首页 > 代码库 > js 下载远程图片

js 下载远程图片

<!DOCTYPE html>
<html lang="en">
<head>
<script src="http://www.mamicode.com/jquery/jquery-1.9.1.min.js"></script>
<script src="http://www.mamicode.com/jquery/jquery.min.js"></script>
<meta charset="UTF-8">
<title>Title</title>
</head>
<body>
js图片下载远程图片
<a href="" id="down">点击下载百度logo图片</a>
<input type="hidden" id="url" value="https://www.baidu.com/img/bd_logo1.png">
</body>
<script type="text/javascript">
$(‘#down‘).click(function(){
var url = $(‘#url‘).val();
var $a = $("<a></a>").attr("href", url).attr("download", "img.png");
$a[0].click();
});
</script>
</html>

js 下载远程图片