我有一些JavaScript,在其中我需要cookie或localstorage以确保变量不会丢失。我是一个初学者,我不确定哪个最好用,但是我知道两者确实是一样的东西。基本上,我需要使用JavaScript进行存储,甚至在用户注销/登录时也要保存任何天数。
有人可以帮忙吗?
<script>
$(document).ready(function() {
$("input").click(function(e) {
e.preventDefault();
var $challenge_div = $(this).parent().parent();
$challenge_div.data("finish", "false");
$challenge_div.removeClass("show").addClass("hide");
var $challenge_list = $("div[class='hide']");
$.each($challenge_list, function() {
var new_challenge = $(this);
if (new_challenge.data("finish") == false) {
new_challenge.removeClass("hide").addClass("show");
return false;
}
});
if ($("div[class='show']").length == 0) {
$("#message p").html("You finished all your challenges !");
}
});
});
</script>
Run Code Online (Sandbox Code Playgroud)