0
我搞砸了一些JavaScript,我試圖找出一種方式來讀取localStorage的方式,所以我可以取得成就每10次點擊或任何事。代碼如下:讀取localStorage數據?
<!DOCTYPE>
<HTML>
<HEAD>
<link rel="stylesheet" type="css/text" href="css.css">
<script>
function clickCounter() {
if(typeof(Storage)!=="undefined")
{
var ten=10;
var value = clickCount;
if (localStorage.clickcount)
{
localStorage.clickcount=Number(localStorage.clickcount)+1;
}
else
{
localStorage.clickcount=1;
}
document.getElementById("result").innerHTML="You have clicked the button " +
localStorage.clickcount + " times.";
}
else
{
document.getElementById("result").innerHTML="Sorry, your browser does not support web
storage...";
}
}
function clickCounterReset() {
localStorage.clear();
localStorage.clickcount=0;
document.getElementById("result").innerHTML="You haven't clicked the button once!";
}
function Ach1() {
if (localStorage.clickcount=10) {
localStorage.setitem("GetData" , value);
alert(localStorage.getitem("GetData"));
document.getElementById("Ach1").innerHTML="Successfully reached 100!";
}
}
</script>
</HEAD>
<BODY class="body">
<br>
<br>
<div id="Ach1"></div>
<br>
<br>
<center>
<div class="noLight">
<div class="pointlessbutton" style="cursor: pointer;" onClick="clickCounter()">
<font color="white" size="4">+1</font>
</div>
<br>
<div class="pointlessbutton" style="cursor: pointer;" onClick="clickCounterReset()">
<font color="white" size="4">Reset</font>
</div>
</div>
<div id="result"></div>
</center>
</BODY>
</HTML>
正如您所看到的,點擊的實際腳本工作正常,所有HTML也是如此。然而,在它所說的「函數Ach1()」的底部,我試圖讓腳本讀取數據,並將它與我放入的值比較,比如10,然後讓它吐出一些HTML包含在漂亮的CSS中並顯示成就。
不確定你想要什麼 - 在你的問題= P中沒有「?」但是......如果我正確地猜出某些東西跳到我身上.....奇怪....是你有'localStorage.clickcount = 10'。你不是指'localStorage.clickcount == 10'嗎? –
對不起,沒有說清楚。如何在10次點擊後顯示成果? – user3089082
此外,我已經嘗試了/ = ==的每個變體,它只是不起作用。 :/ – user3089082