<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Document</title>
<script src="https://code.jquery.com/jquery-3.3.1.min.js"></script>
<style>
.active{
background-color: red;
}
</style>
</head>
<body>
<div class="fn_switch" data-name="11">1</div><div></div>
<div class="fn_switch" data-name="12">2</div><div></div>
<div class="fn_switch" data-name="13">3</div><div></div>
<div class="fn_switch" data-name="14">4</div><div></div>
<div class="fn_switch" data-name="15">5</div><div></div>
<div class="fn_switch" data-name="16">6</div><div></div>
<div class="fn_switch" data-name="17">7</div><div></div>
<script>
$(function(){
$('.fn_switch').click(function(e){
e.preventDefault();
$(this).next().slideToggle(300);
if ($(this).hasClass('active')) {
$(this).removeClass('active');
}
else {
$(this).addClass('active');
}
var arr = $.map($('.fn_switch'), function(el, i){
if($(el).hasClass('active')) return $(el).attr('data-name');
});
localStorage.setItem('a', JSON.stringify(arr));
});
$('.fn_switch').filter(function(i){
return JSON.parse(localStorage.getItem('a')).includes($(this).attr('data-name'));
}).addClass('active').next().show();
});
</script>
</body>
</html>
</script>
</body>
</html>