[英]Store loop's value in localStorage
Good day! 美好的一天! I have this code, which show/hide elements when checkboxes are checked/unchecked. 我有这段代码,当选中/取消选中复选框时,它们会显示/隐藏元素。
So it works nice, but I want to store some user's choice in localStorage
and even after reloading the page this choice will remain. 因此效果很好,但我想将一些用户的选择存储在localStorage
,即使在重新加载页面后,该选择仍将保留。 As you can see I am using loop to check which checkboxes
are true. 如您所见,我正在使用循环来检查哪些checkboxes
是正确的。 I have never used localStorage
before, so any advice and suggestions will be appreciated. 我以前从未使用过localStorage
,因此将不胜感激。
This code is an answer to my question. 此代码是我的问题的答案。
var showHideColInTablle = function () {
console.log(checkboxToTdBinding);
var checkedList = checkboxToTdBinding.map(function (checkBox) {
var c = {};
c[checkBox.checkbox.attr('id')] = checkBox.checkbox.is(":checked");
return c
});
localStorage['checked'] = JSON.stringify(checkedList);
console.log(typeof localStorage['checked'])
};
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.