我对所有这些都很陌生,但这是我的问题我有一个弹出窗口,上面写着"不要再显示这个"复选框。当用户选中此选项时,本地存储应该保存客户端id(在db中)和复选框的选中状态。根据这两个因素,应该显示或隐藏弹出窗口
下面是我的代码:$(document).ready(function () {
$('#beforelight').css('display', 'block');
$PopUp = $('#beforelight');
var hide = JSON.parse(localStorage.getItem('hide'));
var id = JSON.parse(localStorage.getItem('[[clientdb.id]]'));
if (hide, id) {
$PopUp.hide();
} else {
// initialize value in case it hasn't been set already
localStorage.setItem('hide', false);
}
$('#checkbox').click(function () {
$('#beforelight').hide();
// toggle the boolean by negating its value
var id = JSON.parse(localStorage.getItem('[[clientdb.id]]'));
var hide = JSON.parse(localStorage.getItem('hide'));
localStorage.setItem('hide', !hide);
});
});
请尝试此代码- JSON。解析返回字符串
$(document).ready(function () {
$('#beforelight').css('display', 'block');
$PopUp = $('#beforelight');
var hide = JSON.parse(localStorage.getItem('hide')) === 'true';
var id = JSON.parse(localStorage.getItem('[[clientdb.id]]'));
if (hide && id) {
$PopUp.hide();
} else {
// initialize value in case it hasn't been set already
localStorage.setItem('hide', 'false');
}
$('#checkbox').click(function () {
$('#beforelight').hide();
// toggle the boolean by negating its value
var id = JSON.parse(localStorage.getItem('[[clientdb.id]]'));
var hide = JSON.parse(localStorage.getItem('hide')) === 'true';
localStorage.setItem('hide', !hide ? 'true' : 'false');
});
});
$(document).ready(function(){
$('#beforelight').css('display', 'block');
$PopUp = $('#beforelight');
var checkbox_status = JSON.stringify(localStorage.getItem('checked'));
var saved_id = JSON.parse(localStorage.getItem('id'));
window.onload = function(){
if(checkbox_status="true" && saved_id == stored_id){
$("#beforelight").hide();
}
else if(checkbox_status="false"){
$("#beforelight").hide();
}
};
$('input[type="checkbox"]').click(function(){
if($(this).is(":checked")){
$('#beforelight' ).hide();
var checked = true;
}
else if($(this).is(":not(:checked)")){
var checked = false;
}
JSON.parse(localStorage.setItem('checked', checked))
// JSON.parse(localStorage.setItem(saved_id+'checked',checked))
});
var stored_id = document.getElementById("client_id").innerHTML;
JSON.stringify(localStorage.setItem('id', stored_id));
});