首页 > 解决方案 > 拆分成这个变量的新行

问题描述

如何拆分成这个变量“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();
}

标签: javascripthtml

解决方案


如果我正确理解您要拆分的内容,则可以将这些行与下一行字符连接起来:

var textToSave = textToSave + "\n" + document.getElementById("inputTextToSave1").value;

推荐阅读