![](/img/trans.png)
[英]Local Storage Only Storing Part Of My data And Nothing is being stored in Session Storage
[英]why is my data being stored in local storage, but is not displaying on the page?
我试图保存我在文本框中输入的一些值,但是,这些值存储在本地存储中,而不是在网页上。 这是 github 上的回购链接: https://github.com/malekmekdashi/work_day_scheduler
这是我的代码的示例:
$('.saveBtn').on('click', function() { var inputValue = $(this).siblings('.description').val(); var timeValue = $(this).parent('id'); localStorage.setItem(inputValue, timeValue); }); $('#item1.description').val(localStorage.getItem('item1'));
<link href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.1.2/css/all.min.css" rel="stylesheet"/> <script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script> <div class="row time-block"> <div class="col-md-1 hour">9am</div> <textarea class="col-md-10 description" id="item1"> </textarea> <button class="saveBtn col-md-1"><i class="fa fa-save"></i></button> </div>
尝试这个!
<link href="https://cdnjs.cloudflare.com/ajax/libs/font-
awesome/6.1.2/css/all.min.css" rel="stylesheet"/>
<script
src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js">
</script>
<div class="row time-block">
<div class="col-md-1 hour">9am</div>
<textarea class="col-md-10 description" id="inputValue"> </textarea>
<textarea class="col-md-10 description" id="timeValue "> </textarea>
<button class="saveBtn col-md-1"><i class="fa fa-save"></i></button>
</div>
和jQuery !
$('.saveBtn').on('click', function() {
var inputValue = $(this).siblings('.description').val();
var timeValue = $(this).parent('id');
localStorage.setItem("inputValue", inputValue );
localStorage.setItem("timeValue ", timeValue );
});
$('#inputValue.description').val(localStorage.getItem('inputValue'));
$('#timeValue .description').val(localStorage.getItem('timeValue '));
值存储在localStorage
中,但在从localStorage
获取值时使用了错误的键:
$('.saveBtn').on('click', function() {
var inputValue = $(this).siblings('.description').val();
var timeValue = $(this).parent('id');
localStorage.setItem(inputValue, timeValue );
});
$('#item1.description').val(localStorage.getItem(inputValue));
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.