本地存储问题(更新var' s)

时间:2016-12-03 14:55:26

标签: javascript html

当我尝试从上一个网页会话中加载已保存的内容时,数字会加载,但变量dosent会更改,这意味着当我按下按钮将1添加到变量而不是添加到上次保存的数字时它会启动所有从一个方向。 继承人代码:



<!DOCTYPE html>
<html>
<head>
</head>
<body>
<button onclick="collectWood()">chop wood</button>
<p>wood:</p>
<p id="woodOut">0</p>
<button onclick="saveData()">save Data</button>
<button onclick="loadData()">load Data</button>
<script>
var wood = localStorage.getItem;

//saves game data
function saveData() {
	localStorage.setItem("woodSave", wood);
}
function loadData() {
	document.getElementById('woodOut').innerHTML = localStorage.getItem("woodSave");
}
//outputs one wood when button is clicked
function collectWood() {
	wood = wood + 1;
	document.getElementById("woodOut").innerHTML = wood;
}
</script>
</body>
</html>
&#13;
&#13;
&#13;

0 个答案:

没有答案