使用jQuery点击按钮下载图像
我的页面中有一张图片。 我希望在单击按钮时下载图像。 我怎么能用jQuery或Javascript做到这一点? 请给我一个小提琴。 小提琴
save.php将返回
“1 | DOWNLOAD_NOS | FULL_PATH | FILE_NAME”或者您可以使用jSON
$('#save_wall').click(function(e) { e.preventDefault(); $.ajax({ type: "POST", url:"save.php", data: "id==$_GET['id'];?>", success: function (dataCheck) { var m=dataCheck.split("|"); if(m[0] == '1') { alert("Thank You for your Download Picture\n\nShortly Picture Download will start..."); $('#save_wall_count').html(m[1]); var a = document.createElement('a'); a.href = m[2]; a.download = m[3]; document.body.appendChild(a); a.click(); document.body.removeChild(a); } if(m[0] == '0') alert("Error: Error in Save Picture or Not Found...\n\n"+ dataCheck); } }); });