需要插件
jszip
file-saver
引入
<script src="~/lib/jszip/jszip.js?t=@jsAndCssVersion"></script>
<script src="~/lib/jszip/FileSaver.min.js?t=@jsAndCssVersion"></script>
使用
var zip = new JSZip();
// 获取iframe 节点
var iframe = document.getElementById("layui-layer-iframe1");
// 获取 iframe 内部的文档
var iframeDoc = iframe.contentDocument || iframe.contentWindow.document;
$.each(iframeDoc.querySelectorAll(".item"), function (i, v) {
const blod = new Blob([$(v).html()], {
type: 'application/file'
})
zip.file( $(v).attr("data-name")+ ".docx", blod);
})
zip.generateAsync({ type: "blob" })
.then(function (content) {
saveAs(content, $(".layui-layer-title").html()+".zip");
});
标签:layer,iframe,zip,前端,导出,content,file,var,压缩包
From: https://www.cnblogs.com/tlf01/p/18660308