我正在使用HTML5下载属性下载特定div的HTML:
var a = document.body.appendChild(
document.createElement("a")
);
a.download = "export.html";
a.href = "data:text/attachment," + document.getElementById("export").innerHTML;
a.innerHTML = "[Export content]";
这可行,但HTML文件连续出现:
<tr><td><p>ADL</p></td><td><p>Some text here.</p></td><td></td></tr><tr><td><p>...
有什么想法吗?
答案 0 :(得分:0)
我能够通过将href更改为以下内容来解决此问题:
a.href = "data:text/plain;charset=utf-8," + encodeURIComponent(code);