Я какое-то время работал над столом для проекта класса, и он работает довольно хорошо (благодаря большому вкладу, который я нашел здесь)
У меня проблемы с получением кнопок, чтобы оставаться активнымикогда страница перезагрузится.Я использую jQuery, и работал с localStorage
и sessionStorage
совсем без результатов.Любая помощь будет принята с благодарностью!
Вот фрагмент:
function toggle(event) { //this is what happens when you click on a button
$(this).toggleClass('active'); //adds an "active" class (color changes)
sessionStorage.setItem("activeDiv", $(this).index('.btn')); //i need help with this
}
$(function() {
"use strict";
$(".btn").on("click ", toggle); // you can set the buttons active or not
var activebtn = sessionStorage.getItem("activeDiv");
if (activebtn) { //I need help with this
$('.btn').toggleClass('active').eq(activebtn).toggleClass('active');
}
});
table,
tr,
td {
background-color: #a3bfd9;
border: solid 2px #41403E;
border-collapse: collapse;
}
.btn {
vertical-align: top;
background-color: #ebd3eb;
border-color: #93e2ff;
font-size: 10px;
width: 100px;
height: 30px;
text-align: center;
text-decoration: none;
display: inline-block;
cursor: pointer;
border-radius: 5px;
}
.btn:hover {
background-color: #93e2ff;
opacity: 0.7;
/*color: #5fc0e3;*/
border-color: #5fc0e3;
transition: 0.3s;
}
.btn.active {
background-color: #899c30;
color: #fff;
border-color: #005fbf;
transition: 0.3s;
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<div class="obsimotable">
<table>
<tr>
<td>
<button class="btn" value="4">Some class 4op</button>
<br>
<button class="btn" value="4">Some class 4op</button>
<br>
<button class="btn" value="4">Some class 4op</button>
<br>
<button class="btn" value="5">Some class 5op</button>
<br>
</td>
<td>
<button class="btn" value="4">Some class 4op</button>
<br>
<button class="btn" value="4">Some class 4op</button>
<br>
<button class="btn" value="4">Some class 4op</button>
<br>
</td>
<td>
<button class="btn" value="3">Some class 3op</button>
<br>
<button class="btn" value="4">Some class 4op</button>
<br>
<button class="btn" value="4">Some class 4op</button>
<br>
</td>
<td>
<button class="btn" value="5">Some class 5op</button>
<br>
<button class="btn" value="13">Some class 13op</button>
<br>
</td>
<td></td>
</tr>
<tr>
<td>
<button class="btn" value="5">Some class 5op</button>
<br>
<button class="btn" value="5">Some class 5op</button>
<br>
<button class="btn" value="4">Some class 4op</button>
<br>
</td>
<td>
<button class="btn" value="4">Some class 4op</button>
<br>
<button class="btn" value="4">Some class 4op</button>
<br>
<button class="btn" value="4">Some class 4op</button>
<br>
</td>
<td>
<button class="btn" value="4">Some class 4op</button>
<br>
<button class="btn" value="3">Some class 3op</button>
<br>
<button class="btn" value="3">Some class 3op</button>
<br>
<button class="btn" value="3">Some class 3op</button>
<br>
<button class="btn" value="4">Some class 4op</button>
<br>
</td>
<td>
<button class="btn" value="6">Some class 6op</button>
<br>
</td>
<td>
<button class="btn" value="3">Some class 3op</button>
<br>
<button class="btn" value="6">Some class 6op</button>
<br>
</td>
</tr>
<tr>
<td>
<button class="btn" value="4">Some class 4op</button>
<br>
<button class="btn" value="6">Some class 6op</button>
<br>
</td>
<td>
<button class="btn" value="6">Some class 6op</button>
<br>
<button class="btn" value="4">Some class 4op</button>
<br>
</td>
<td>
<button class="btn" value="4">Some class 4op</button>
<br>
<button class="btn" value="4">Some class 4op</button>
<br>
<button class="btn" value="4">Some class 4op</button>
<br>
</td>
<td>
<button class="btn" value="4">Some class 4op</button>
<br>
<button class="btn" value="4">Some class 4op</button>
<br>
</td>
<td>
<button class="btn" value="3">Some class 3op</button>
<br>
</td>
</tr>
</table>