0

新手来了 使用 html 和 Javascript。它一直在工作,直到我添加了一个侧面菜单。我在下载功能下的侧面菜单中使用提交按钮进行了设置。我只包含了前几个问题和答案的代码。图像本地存储有时会起作用。我在notepad++和chrome上运行它。

function save() {


  //question1
  var question1 = document.getElementById("question1")
  var correctanswer1 = document.getElementById("correctanswer1");
  var incorrect11 = document.getElementById("incorrect11");
  var incorrect12 = document.getElementById("incorrect12");
  var incorrect13 = document.getElementById("incorrect13");

  try {

    //question1
    localStorage.setItem("question1", question1.value);
    sessionStorage.setItem("question1", question1.value);
    localStorage.setItem("correctanswer1", correctanswer1.value);
    sessionStorage.setItem("correctanswer1", correctanswer1.value);
    localStorage.setItem("incorrect11", incorrect11.value);
    sessionStorage.setItem("incorrect11", incorrect11.value);
    localStorage.setItem("incorrect12", incorrect12.value);
    sessionStorage.setItem("incorrect12", incorrect12.value);
    localStorage.setItem("incorrect13", incorrect13.value);
    sessionStorage.setItem("incorrect13", incorrect13.value);

    //question 1
    question1value = "";
    correctanswer1value = "";
    incorrect11.value = "";
    incorrect12.value = "";
    incorrect13.value = "";


  } catch (e) {
    if (e == QUOTA_EXCEEDED_ERR) {
      console.log("Error: Local Storage limit exceeds.");
    } else {
      console.log("Error: Saving to local storage.");
    }
  }
}
<div id="sidebar">

  <ul>
    <a href="#" id="scroll-to-bottom">Top of Page</a>
    <p><a href="javascript://Save as TXT" id="submitLink">Download </a></p>
    <p>
      <a href="" id="Save" onclick="myFunction()">Submit</a> </ul>
  </p>


</div>

<div class="center">


  Enter Question 1:

  <input type="text" id="question1" name="Question 1" size="40">

  <br>

  <br> Next, add a correct answer
  <font color="#51096F"> FIRST </font> and then the incorrect answers for your question.

  <br>

  <p>

    <input type="text" id="correctanswer1" name="correctanswer1" size="50" style="border:2px solid #660570">

  </p>

  <p>

    <input type="text" id="incorrect11" name="incorrect11" size="50">

  </p>

  <p>

    <input type="text" id="incorrect12" name="incorrect12" size="50">

  </p>

  <p>

    <input type="text" id="incorrect13" name="incorrect13" size="50">

  </p>

  <br>

  <img id="uploadPreview1" style="width: 100px; height: 100px;" />

  <input id="uploadImage1" type="file" name="myPhoto1" onchange="PreviewImage1();" />

  <script type="text/javascript">
    function PreviewImage1() {

      var oFReader = new FileReader();

      oFReader.readAsDataURL(document.getElementById("uploadImage1").files[0]);

      oFReader.onload = function(oFREvent) {

        document.getElementById("uploadPreview1").src = oFREvent.target.result;

        sessionStorage.setItem("image", oFREvent.target.result);

        localStorage.setItem("image", oFREvent.target.result);

      };

    };
  </script>
</div>

4

0 回答 0