我具有单击时将 div 的样式保存并清除到 localStorage 的功能:
var originalAttributes = $('.aaa').attr('style');
$('.aaa').each(function(){
var d = $(this),
id = d.attr('id'),
storedStyle = window.localStorage.getItem('aaaStyle' + id);
if (storedStyle != undefined){ //style stored
d.attr('style', storedStyle);
}
});
//mouse event functions for class="aaa"
$('#save').click(function () {
$('.aaa').each(function(){
var d = $(this),
id = d.attr('id'),
style = d.attr('style');
if (style != originalAttributes){ //style changed
//$.cookie('aaaStyle' + id, style, { expires: 30 });
window.localStorage.setItem('aaaStyle' + id, style);
}
});
});
$('#clear').click(function () {
// unset changes
$('.aaa').attr('style',originalAttributes).each(function(){
var d = $(this),
id = d.attr('id');
window.localStorage.removeItem('aaaStyle' + id);
});
});
应该在此代码中添加什么以便压缩本地存储中的数据?
(每个浏览器的每个域都有内存限制,我想最大化这个功能)