Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/html/76.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
我有两个按钮onclick change text按钮和n';t save我想在javascript中使用本地存储保存更改_Javascript_Html - Fatal编程技术网

我有两个按钮onclick change text按钮和n';t save我想在javascript中使用本地存储保存更改

我有两个按钮onclick change text按钮和n';t save我想在javascript中使用本地存储保存更改,javascript,html,Javascript,Html,我尝试了很多方法,但都不管用。有什么问题? 代码 html 这是代码。它可以工作,但如果重新加载,按钮将按原样返回。你犯了什么错误 <button class="button" id="button1">click 1</button> <button class="button" id="button2">click 2</button> var activeBut

我尝试了很多方法,但都不管用。有什么问题? 代码 html

这是代码。它可以工作,但如果重新加载,按钮将按原样返回。你犯了什么错误

<button class="button" id="button1">click 1</button>
<button class="button" id="button2">click 2</button>
var activeButton = localStorage.getItem('activeButton');
var isActive = localStorage.getItem('isActive');
const allButtons = document.querySelectorAll(".button");
[...allButtons].forEach(function (thisButton) {
    if (isActive === 'true') {
        if (activeButton !== thisButton.id) {
            thisButton.disabled = true;
        }
    }
});
const movetool = event => {
    activeButton = localStorage.getItem('activeButton');
    if (activeButton === target.id) {
        var enableAll = false;
        let saveuser = localStorage.getItem("save_unsave");
        var setName = "don't click";
        localStorage.setItem("Name", setName);
        target.innerHTML = localStorage.getItem("Name");
        Array.from(allButtons).forEach(function (thisButton) {
            if (thisButton.disabled) {
                enableAll = true;
                return;
            }
        });
        if (enableAll) {
            Array.from(allButtons).forEach(function (thisButton) {
                thisButton.disabled = false;
                target.innerHTML = "click";
            });
            localStorage.setItem('isActive', false);
        } else {
            Array.from(allButtons).forEach(function (thisButton) {
                thisButton.disabled = true;
                thisButton.innerHTML = "don't click";
                var setName = "don't click";
                localStorage.setItem("Name", setName);
                target.innerHTML = localStorage.getItem("Name");
            });
            if (target.classList.contains("button")) {
                target.disabled = false;
                localStorage.setItem('isActive', true);
                localStorage.setItem('activeButton', target.id);
            }
        }
    } else {
        Array.from(allButtons).forEach(function (thisButton) {
            thisButton.disabled = true;
            thisButton.innerHTML = "don't click";
            var setName = "clicked";
            localStorage.setItem("Name", setName);
            target.innerHTML = localStorage.getItem("Name");
        });
        if (target.classList.contains("button")) {
            target.disabled = false;
            localStorage.setItem('isActive', true);
            localStorage.setItem('activeButton', target.id);
        }
    }
}
document.querySelector('.button_container').addEventListener('click', movetool);