如何将此变量“ textToSave”拆分为新行
function saveTextAsFile() {
var textToSave = document.getElementById("inputTextToSave").value;
var textToSave = textToSave + document.getElementById("inputTextToSave1").value;
var textToSaveAsBlob = new Blob([textToSave], { type: "text/plain" });
var textToSaveAsURL = window.URL.createObjectURL(textToSaveAsBlob);
var fileNameToSaveAs = document.getElementById("inputFileNameToSaveAs").value;
var downloadLink = document.createElement("a");
downloadLink.download = fileNameToSaveAs;
downloadLink.innerHTML = "Download File";
downloadLink.href = textToSaveAsURL;
downloadLink.onclick = destroyClickedElement;
downloadLink.style.display = "none";
document.body.appendChild(downloadLink);
downloadLink.click();
}
答案 0 :(得分:0)
如果我正确理解了要分割的内容,则可以将这些行与下一行字符连接起来:
var textToSave = textToSave + "\n" + document.getElementById("inputTextToSave1").value;