繁体   English   中英

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

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

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

链接到我的 github 回购: https://github.com/malekmekdashi/work_day_scheduler

我似乎无法解决我遇到的这个问题。 我的目标是,每当我在文本框中输入一些值后刷新页面时,这些值将与本地存储一起保留在页面上。 但是,我无法这样做。 如果有人可以帮助我解决这个问题,我将不胜感激。 这是我正在使用的代码的一个小示例

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:

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

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

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

您的选择器在两个方面是错误的。

  1. 就像评论中已经说过的那样:您的回报将是一个数组。 您有多个带有 class description的 ids inputValue

  2. 您想要 select id inputValue ,这意味着您需要使用#inputValue 此外,您还需要通过省略空格来组合它们,否则您将搜索儿童。 正确的 jQuery 将是$('#inputValue.description')

暂无
暂无

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

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