java脚本本地存储停止工作

时间:2018-05-03 18:22:40

标签: javascript html local-storage

新手在这里。使用html和Javascript。它一直在工作,直到我添加了侧面菜单。我在下载功能下的侧边菜单中设置了提交按钮。我只包括前几个问题和答案的代码。图像本地存储有时会工作。我在记事本++和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>
&#13;
&#13;
&#13;

0 个答案:

没有答案