javascript - 拆分成这个变量的新行
问题描述
如何拆分成这个变量“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();
}
解决方案
如果我正确理解您要拆分的内容,则可以将这些行与下一行字符连接起来:
var textToSave = textToSave + "\n" + document.getElementById("inputTextToSave1").value;
推荐阅读
- resharper-9.0 - 为什么 resharper 在文件中添加 // unsed 注释
- html - 我无法点击无序列表中的链接
- node-sass - 使用 NPM 安装包的问题
- javascript - 从本地 API 获取数据
- python - 如何使用 Python 动态创建列表字典
- file - 有没有办法将流重定向到 lua 中的标准输入
- node.js - 如何在云消息传递触发函数中引用 Firebase 实时数据(在标题或正文中使用)
- php - Laravel Cashier - 终身订阅
- virtualbox - VERR_SUP_VP_UNEXPECTED_VALID_PATH_COUNT
- android - Kotlin RecyclerView onItemClick