需要一个本地存储值来增加按钮按下
Need a local storage value to increase on button press
我需要将一个值保存到 localstorage 中,该值已经在 localstorage 中并且只增加 1
保存:
function checkklaar2() {
a = document.getElementById("eindgetal2").value;
if (a == "0") {
window.location.href = 'winnaar2.html';
var gewonnen2 = localStorage.getItem("setsgewonnen2");
localStorage.setItem("setsgewonnen2.2", gewonnen2.value + "1");
} else {}
}
查看:
// Check browser support
if (typeof(Storage) != "undefined") {
// Store
// Retrieve
document.getElementById("result1.1").innerHTML = localStorage.getItem("naamspeler1.1");
document.getElementById("result2.1").innerHTML = localStorage.getItem("naamspeler2.1");
document.getElementById("result1.2").value = localStorage.getItem("setsgewonnen1.2");
document.getElementById("result2.2").value = localStorage.getItem("setsgewonnen2.2");
document.getElementById("sets").value = localStorage.getItem("setstespelen");
document.getElementById("sets2").value = localStorage.getItem("setstespelen");
} else {
document.getElementById("result").innerHTML = "Sorry, your browser does not support Web Storage...";
}
接收输入,因为它没有显示第 2 页输入中的值:
HTML:
<h1 style="margin-left:15px;">Speler<div id="result1.1"></div> </h1>
<div class="list-block">
<ul>
<div class="list-block">
<ul>
<li>
<div class="item-content">
<div class="item-title label">Sets gewonnen</div>
<div class="item-input">
<input type="number" id="result1.2">
</div>
</div>
</li>
</ul>
<ul>
<li>
<div class="item-content">
<div class="item-title label">Sets totaal</div>
<div class="item-input">
<input type="number" id="sets">
</div>
</div>
</li>
</ul>
</div>
</ul>
</div>
<h1 style="margin-left:15px;">Speler <div id="result2.1"></div></h1>
<div class="list-block">
<ul>
<div class="list-block">
<ul>
<li>
<div class="item-content">
<div class="item-title label">Sets gewonnen</div>
<div class="item-input">
<input type="number" id="result2.2">
</div>
</div>
</li>
</ul>
<ul>
<li>
<div class="item-content">
<div class="item-title label">Sets totaal</div>
<div class="item-input">
<input type="number" id="sets2">
</div>
</div>
</li>
提前致谢!
我想你正在搜索这样的东西:
localStorage.setItem("setsgewonnen2.2", parseInt(gewonnen2.value) + 1);
通常本地存储将所有内容存储为字符串
我需要将一个值保存到 localstorage 中,该值已经在 localstorage 中并且只增加 1
保存:
function checkklaar2() {
a = document.getElementById("eindgetal2").value;
if (a == "0") {
window.location.href = 'winnaar2.html';
var gewonnen2 = localStorage.getItem("setsgewonnen2");
localStorage.setItem("setsgewonnen2.2", gewonnen2.value + "1");
} else {}
}
查看:
// Check browser support
if (typeof(Storage) != "undefined") {
// Store
// Retrieve
document.getElementById("result1.1").innerHTML = localStorage.getItem("naamspeler1.1");
document.getElementById("result2.1").innerHTML = localStorage.getItem("naamspeler2.1");
document.getElementById("result1.2").value = localStorage.getItem("setsgewonnen1.2");
document.getElementById("result2.2").value = localStorage.getItem("setsgewonnen2.2");
document.getElementById("sets").value = localStorage.getItem("setstespelen");
document.getElementById("sets2").value = localStorage.getItem("setstespelen");
} else {
document.getElementById("result").innerHTML = "Sorry, your browser does not support Web Storage...";
}
接收输入,因为它没有显示第 2 页输入中的值:
HTML:
<h1 style="margin-left:15px;">Speler<div id="result1.1"></div> </h1>
<div class="list-block">
<ul>
<div class="list-block">
<ul>
<li>
<div class="item-content">
<div class="item-title label">Sets gewonnen</div>
<div class="item-input">
<input type="number" id="result1.2">
</div>
</div>
</li>
</ul>
<ul>
<li>
<div class="item-content">
<div class="item-title label">Sets totaal</div>
<div class="item-input">
<input type="number" id="sets">
</div>
</div>
</li>
</ul>
</div>
</ul>
</div>
<h1 style="margin-left:15px;">Speler <div id="result2.1"></div></h1>
<div class="list-block">
<ul>
<div class="list-block">
<ul>
<li>
<div class="item-content">
<div class="item-title label">Sets gewonnen</div>
<div class="item-input">
<input type="number" id="result2.2">
</div>
</div>
</li>
</ul>
<ul>
<li>
<div class="item-content">
<div class="item-title label">Sets totaal</div>
<div class="item-input">
<input type="number" id="sets2">
</div>
</div>
</li>
提前致谢!
我想你正在搜索这样的东西:
localStorage.setItem("setsgewonnen2.2", parseInt(gewonnen2.value) + 1);
通常本地存储将所有内容存储为字符串