[英]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.