在本地存储中存储显示为调试器和未定义的2个值 [英] Store In localStorage is showing 2 values as debugger and Undefined

查看:44
本文介绍了在本地存储中存储显示为调试器和未定义的2个值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是Buildig普通HTML并实现CSS和Javascript.当我将任务存储在我的 localStorage 中时,它存储在 localStorage 但它正在打印两个值,一个是我的任务,这些是我的所有代码,请告诉我可以解决这个调试器的方法..另一个未显示为调试器的显示..

I am Buildig Normal HTML And Materialize Css And Javascript. When i am storing tasks in my localStorage it was Storing on localStorage But it was Printing Two Values one is My Tasks and These is All Of my code and Please Tell the way i can solve this debugger.. Another Showing As Debugger undefined..

What is Debugger and undefined and Why It was Showing ..?
Please View The Code..!

在本地存储中,我很喜欢

in Local Storage I am Getting Like

Key     Value
tasks   ["Walk the Dog"]
debugger undefined
Thank You

const form = document.querySelector('#task-form');
const filter = document.querySelector('#filter');
const taskList = document.querySelector('.collection');
const taskInput = document.querySelector('#task');
const clearBtn = document.querySelector('.clear-tasks');


loadEventListeners();

function loadEventListeners(){
    form.addEventListener('submit', addTask);
    taskList.addEventListener('click', removeTask);
    clearBtn.addEventListener('click',clearTasks);
    filter.addEventListener('keyup', filterLi)
}

function addTask(e){
    if(taskInput.value ===''){
        alert('Please Add Task');
    } else {
    const li = document.createElement('li');
    li.className = 'collection-item';
    li.appendChild(document.createTextNode(taskInput.value));
    const link = document.createElement('a');
    link.className = 'delete-item secondary-content';
    link.innerHTML = '<i class="fa fa-remove"></i>'
    li.appendChild(link);
    taskList.appendChild(li);
    storeTaskInLocalStorage(taskInput.value);
    e.preventDefault();

    taskInput.value="";

}}

function storeTaskInLocalStorage(task){
    let tasks;
    if(localStorage.getItem('tasks') === null){
        tasks = [];
    } else{
        tasks = JSON.parse(localStorage.getItem('tasks'));
    }
    tasks.push(task);
    localStorage.setItem('tasks', JSON.stringify(tasks));
}

function removeTask(e){
    if(e.target.parentElement.classList.contains('delete-item')){
        e.target.parentElement.parentElement.remove();
    }
}

function clearTasks(){
    while(taskList.firstChild){
        taskList.removeChild(taskList.firstChild)
    }
}

function filterLi(e){
    const filterText = e.target.value.toLowerCase();
    document.querySelectorAll('.collection-item').forEach(function(task){
        const litem = task.firstChild.textContent;
        if(litem.toLowerCase().indexOf(filterText) != -1){
            task.style.display = 'block'
        } else{
            task.style.display = 'none';
        }
    })
}

推荐答案

您可以忽略密钥,因为您没有通过应用程序添加密钥.在使用sockets.io时,我注意到类似的东西,但是您没有在使用sockets.io.

You can ignore the key as you are not adding it though your app. I've noticed something similar when using sockets.io but you are not using sockets.io.

如果它困扰您,您可以自己删除该钥匙.

If it bothers you, you can remove that key yourself.

// Run this in your console 
localStorage.removeItem('debugger');

这篇关于在本地存储中存储显示为调试器和未定义的2个值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆