因此,我們有一個結帳和結帳,你可以選擇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')值。 –
您有沒有對我的最新編輯有任何好運? –