如何在表单提交后保留文本(如何在提交后不删除自己?)

How to persist text after a form submit (how to not delete itself after submit?)

如何在文本框中保存和重新填充文本?每次点击保存时,文本输入框中的旧文本被移除,不应该被移除。

我想做一个在线编辑器,我需要能够保存当前文本而不需要在保存后将文本从textarea框中移除。

var types = [
      {"extension": ".html", "name": "HTML"},
      {"extension": ".txt", "name": "Plain Text"},
      {"extension": ".js", "name": "Javascript"},
      {"extension": ".css", "name": "CSS"},
    ];
types.forEach(function(type) {
  $opt = $("<option>").attr("value", type.extension).text(type.name)
  $("#saveas").append($opt)
});

function SaveAsType() {
  console.log($("#saveas").val());

  {
    var textToSave = document.getElementById("inputTextToSave").value;
    var textToSaveAsBlob = new Blob([textToSave], {
      type: "text/plain"
    });
    var textToSaveAsURL = window.URL.createObjectURL(textToSaveAsBlob);
    var fileNameToSaveAs = document.getElementById("inputFileNameToSaveAs").value + "" + $("#saveas").val();

    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();
  }

}

function destroyClickedElement(event) {
  document.body.removeChild(event.target);
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.min.js"></script>
<textarea id="inputTextToSave" name="inputTextToSave" rows="10" cols="70" placeholder="Type your text here:"></textarea>
    <br>
    <textarea id="inputFileNameToSaveAs" rows="1" cols="70" placeholder=" Filename Save As " style="resize:none;"></textarea>
    <br>
    <script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
    <script src="jquery.min.js"></script>
    Save as
    <select id="saveas">
      <option value="">Defoult ´´ TXT ´´ file or type your own file type</option>
      <option value=".html">´´ HTML ´´ file</option>
      <option value=".js">´´ JS ´´ file</option>
      <option value=".css">´´ CSS ´´ file</option>
      <option value=".txt">´´ TXT ´´ file</option>
    </select><button onclick="SaveAsType();">Save</button>

这个问题在页面上停留了较长时间后,我自己找到了答案。这实际上是非常简单的解决方案。

我刚刚更改了:

<button onclick="SaveAsType();">Save</button>

进入

<input type="button" onClick="SaveAsType();" value=" Save ">

还有 WALLAH,现在文本保存在文本区域后会保留而不会被删除。

注意:我会将问题保留在网上,以供那些可能有相同问题或问题但不知道如何解决的人使用。解决方案是多么简单以及我如何看到它是愚蠢的。