因此,我们有一个结帐和结帐,你可以选择2个插件,现在我似乎遇到的问题是确定这些选项是否打勾或显示正确的样式,所以让我们说我检查了两个选项到付款页面,然后取消它保存,他们被检查,但不显示样式。本地存储存储如果复选框已被点击
我的初步修复是为了在单击插件时在localstorage中保存var,然后在页面加载时(如果localstorage包含它),然后将样式应用于插件,但是我似乎无法获得它适用于它将只适用于1请参阅下面我的jQuery。
$(function() {
addonClass = function(e) {
$(e).toggleClass("addon-active");
$(e).find("label .add").toggle(400);
$(e).find("label .added").toggle(800);
if ($(window).width() < 600) {
$(e).find("label .fiver").toggle(400);
}
}
if (localStorage.getItem('addonooh') === "true") {
addonClass('.first');
$('.first').find('.add, .fiver').hide();
$('.last').find('.fiver').show();
} else if (localStorage.getItem('addon') === "true") {
addonClass('.last');
$('.last').find('.add, .fiver').hide();
$('.first').find('.fiver').show();
} else if (localStorage.getItem('addonooh') === "true" && localStorage.getItem('addonvm') === "true") {
addonClass('.first, .last');
$('.first, .last').find('.fiver').show();
} else {
}
if ($(window).width() > 600) {
$(".additional-features__item").hover(function() {
$(this).toggleClass("addon-active-hover");
$(this).find("label .fiver").stop(true, true).toggle(400);
$(this).find("label .add").stop(true, true).toggle(800);
if ($(this).hasClass('addon-active')) {
$(this).find("label .fiver, label .add").hide();
}
});
}
if ($(window).width() < 600) {
$(this).find("label .add").remove();
}
$(".additional-features__item").click(function() {
if ($(this).hasClass('first')) {
localStorage.addonooh = 'true';
} else {
localStorage.addonvm = 'true';
}
if ($(this).hasClass('.first') && ($(this).hasClass('.addon-active'))) {
localStorage.addonooh = '';
} else if ($(this).hasClass('.last') && ($(this).hasClass('.addon-active'))) {
localStorage.addonvm = '';
}
addonClass(this);
var checkbox = $(this).find(".mobile-answering__standard-feature");
checkbox.prop('checked', !checkbox.prop('checked'));
});
});
感谢这个这个已经得到了大部分的工作我遇到的唯一问题进行更改现在是当我取消选中一个它不清除本地存储我有一种感觉,它与这一点的代码。 ($(this).hasClass('。first')&&($(this).hasClass('.addon-active'))){ localStorage.addonooh =''; ($(this).hasClass('。last')&&($(this).hasClass('.addon-active'))){ localStorage.addonvm =''; } – nSmed
您还没有在代码中指定要取消选中清除local storage的任何位置。这个逻辑会在'$(“。additional-features__item”)下执行。click(function(){'click handler。你不应该把值设置成简单的'true',而是设置为'true'或'false'取决于复选框的$(this).prop('checked')值。 –
您有没有对我的最新编辑有任何好运? –