【发布时间】:2017-07-05 01:40:54
【问题描述】:
我之前问过一个类似的问题,但运气不佳,所以我希望这次有人能帮助我。在我的绘图应用程序中,我有一个保存按钮,允许用户将图像作为 jpg 保存到他们的下载中。我在点击下载按钮时有一个 SweetAlert 提示,警告用户他们是否要保存,但我的问题是它在没有用户输入的情况下无论如何都会保存。有人可以告诉我如何阻止它自行下载吗?我试过 e.preventDefault();没有运气..欢迎张开双臂回答代码示例非常感谢
****************HTML**********************
<div>
<a href="#" class="download" id="downloadLink" download="img.jpg">
<img src="./assets/tools/save.png" />
</a>
</div>
****************JAVASCRIPT**********************
$('#downloadLink').click(function (event) {
swal({ title: "Are you sure you want to save?",
text: "This will save to your downloads",
type: "warning",
showCancelButton: true,
confirmButtonColor: "#f8c1D9",
confirmButtonText: "Yes, save it!",
closeOnConfirm: true
},
function (isConfirm) {
if (isConfirm) {
//swal("Deleted!");
var dt = canvas.toDataURL('image/jpeg');
this.href = dt;
return true;
} else {
}
return false;
});
});
【问题讨论】:
标签: javascript jquery if-statement html5-canvas sweetalert