我使用JS-Cookie制作一个简单的点击游戏。当我调用函数时,它会工作一次,但之后我必须刷新函数才能再次工作。我已经尝试在它之后添加console.log来帮助调试它,并且日志显示,但是cookie。Set不工作了。我不知道发生了什么,我不太熟悉这个库,所以任何帮助都是感激的。
Javascript
(function refreshCookies(i) {
setTimeout(function () {
let flame = Cookies.get('flame');
let gems = Cookies.get('gems');
let cuid = Cookies.get('CUID');
let username = Cookies.get('username');
let value = Cookies.get('value');
let value_amount = document.getElementById('value-amount');
let flame_amount = document.getElementById('flame-amount');
let gem_amount = document.getElementById('gem-amount');
let board_placing = document.getElementById('board-placing');
let welcome_username = document.getElementById('welcome-username');
let username_header = document.getElementById('username-header');
let title = document.getElementById('title');
value_amount.innerHTML = "$" + value;
flame_amount.innerHTML = "<i class="fas fa-fire-alt"></i> " + flame;
gem_amount.innerHTML = "<i class="fas fa-gem"></i> " + gems;
welcome_username.innerHTML = "Welcome, " + username + "!";
username_header.innerHTML = username;
title.innerHTML = "Shoe Clicker - $" + value;
if (--i) {
refreshCookies(i);
}
}, 0500);
})(Infinity);
// clicker
function addClick() {
Cookies.set('value', parseInt(value) + 1);
console.log('click added!');
}