简体   繁体   English

为什么刷新页面后我在页面上的输入消失了,但是输入保存在控制台的本地存储中?

[英]Why do my inputs on the page disappear after refreshing the page, but the inputs are saved in local storage in the console?

link to my web application: https://malekmekdashi.github.io/work_day_scheduler/链接到我的 web 应用程序: https://malekmekdashi.github.io/work_day_scheduler/

link to my github repo: https://github.com/malekmekdashi/work_day_scheduler链接到我的 github 回购: https://github.com/malekmekdashi/work_day_scheduler

I cannot seem to solve this issue that I'm having.我似乎无法解决我遇到的这个问题。 My goal is that whenever I refresh the page after inputting some values in the text box, the values will remain on the page along with local storage.我的目标是,每当我在文本框中输入一些值后刷新页面时,这些值将与本地存储一起保留在页面上。 However, I am unable to do so.但是,我无法这样做。 If someone can be so kind as to help me solve this issue, I would greatly appreciate it.如果有人可以帮助我解决这个问题,我将不胜感激。 Here is a little example of the code that I'm working with这是我正在使用的代码的一个小示例

HTML: <div class="row time-block" id="1"> <div class="col-md-1 hour" id="1">9am</div> <textarea class="col-md-10 description" id="inputValue"></textarea> <button class="saveBtn col-md-1"><i class="fa fa-save"></i></button> </div> HTML: <div class="row time-block" id="1"> <div class="col-md-1 hour" id="1">9am</div> <textarea class="col-md-10 description" id="inputValue"></textarea> <button class="saveBtn col-md-1"><i class="fa fa-save"></i></button> </div>

Javascript: Javascript:

$('.saveBtn').on('click', function() { var inputValue = $(this).siblings('.description').val();

localStorage.setItem("inputValue", inputValue);});

$('inputValue.description').val(localStorage.getItem('inputValue'));

Your selector is wrong in two ways.您的选择器在两个方面是错误的。

  1. Like in the comments already said: Your return will be an array.就像评论中已经说过的那样:您的回报将是一个数组。 You have multiple ids inputValue with class description .您有多个带有 class description的 ids inputValue

  2. You want to select id inputValue , which means you need to use #inputValue .您想要 select id inputValue ,这意味着您需要使用#inputValue Also you need to combine them by leaving out the whitespace otherwise you search for childrens.此外,您还需要通过省略空格来组合它们,否则您将搜索儿童。 Correct jQuery would be $('#inputValue.description')正确的 jQuery 将是$('#inputValue.description')

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM