其實很簡單,html
首先須要兩個js文件jquery
jquery.min.jscanvas
直接上代碼,幾行就解決了url
<a id="example1" onclick="exportGrid()" >導出圖表</a>
//導出圖表 function exportGrid() { html2canvas($("#exportGrid"), { allowTaint: true, taintTest: false, onrendered: function (canvas) { //canvas.id = "mycanvas"; //document.body.appendChild(canvas); //生成base64圖片數據 var url = canvas.toDataURL(); //如下代碼爲下載此圖片功能 var triggerDownload = $("<a>").attr("href", url).attr("download", (new Date()).getTime() + "girds.png").appendTo("body"); triggerDownload[0].click(); triggerDownload.remove(); } }); }
解決了你的問題的話,點個讚唄spa