//输出图片
function exportCanvasAsPNG(id, fileName) {
//获取canvas元素
var canvasElement = document.getElementById(id);
//图片类型
var MIME_TYPE = "image/png";
//转换成base64
var imgURL = canvasElement.toDataURL(MIME_TYPE);
//创建一个a链接,模拟点击下载
var dlLink = document.createElement('a');
dlLink.download = fileName;
dlLink.href = imgURL;
dlLink.dataset.downloadurl = [MIME_TYPE, dlLink.download, dlLink.href].join(':');
console.log(dlLink);
document.body.appendChild(dlLink);
dlLink.click();
document.body.removeChild(dlLink);
}
//var canvas = document.getElementById('fabrictable');
exportCanvasAsPNG('fabrictable','我的搭配');
弄一个链接,模拟点击