的JavaScript
function saveTextAsFile()
{
var textToWrite = document.getElementById('out').innerHTML;
var textFileAsBlob = new Blob([textToWrite], {type:'text/plain'});
var fileNameToSaveAs = document.getElementById("maze").value;
var downloadLink = document.createElement("a");
downloadLink.href = window.webkitURL.createObjectURL(textFileAsBlob);
downloadLink.download = fileNameToSaveAs;
downloadLink.click();
}
我正在尝试将文本从<pre id="out"></pre>
保存到.txt文件,但该函数不保存<pre>
标记中的空格和行间距,我只能看到一个长行新的.txt文件。我在这里缺少什么?
<pre>
包含'\ r \ n'