gpt4 book ai didi

javascript - 单击时将值保存在 LocalStorage 中?

转载 作者:行者123 更新时间:2023-11-28 08:25:08 24 4
gpt4 key购买 nike

每次用户单击向上或向下时都尝试将此值保存到本地存储???

<script>
var Clicks = 800;
function UpClick() {
Clicks = Clicks + 25;
document.getElementById('CountedClicks').innerHTML = Clicks + '';
if (Clicks > 950) {
Clicks = 950;
}
}
function DownClick() {
Clicks = Clicks - 25;
document.getElementById('CountedClicks').innerHTML = Clicks + '';
if (Clicks <= 0) {
Clicks = 25;
}
}
</script>

<span id="CountedClicks">800</span>
<input type="image" src="http://findicons.com/files/icons/2332/super_m/64/navigation_up_button.png" name="1462_EXPOSURE_TI_UP" value="1462_EXPOSURE_TI_UP_BUTTON_WAS_CLICKED" onclick="UpClick()" />

<input type="image" src="http://findicons.com/files/icons/2332/super_mono/64/navigation_down_button.png" name="1462_EXPOSURE_TI_DOWN" value="" onclick="DownClick()" />

将其制作成jsfiddle:http://jsfiddle.net/JRxcr/6/

似乎无法掌握 getItem 或 setItem 的窍门,已经阅读了数小时的 Material ,只是没有得到它希望有人可以提供帮助

谢谢...

最佳答案

这些是我在做实验时想到的。

window.localStorage.setItem('点击次数', 20);

window.localStorage.getItem('点击次数');

所以一切都会像......

<script>
var Clicks = 800;
function UpClick() {
Clicks = Clicks + 25;
document.getElementById('CountedClicks').innerHTML = Clicks + '';
document
if (Clicks > 950) {
Clicks = 950;
}
}
function DownClick() {
Clicks = Clicks - 25;
document.getElementById('CountedClicks').innerHTML = Clicks + '';
if (Clicks <= 0) {
Clicks = 25;
}
}

function SaveClicks(){
window.localStorage.setItem('clicks',Clicks);
}

function GetClicks(){
return window.localStorage.getItem('clicks');
}

</script>

<span id="CountedClicks">800</span>
<input type=
"image" src="http://findicons.com/files/icons/2332/super_mono/64/navigation_up_button.png" name="1462_EXPOSURE_TI_UP" value=
"1462_EXPOSURE_TI_UP_BUTTON_WAS_CLICKED" onclick="UpClick();SaveClicks();" />

<input type="image" src="http://findicons.com/files/icons/2332/super_mono/64/navigation_down_button.png" name="1462_EXPOSURE_TI_DOWN" value="" onclick="DownClick();SaveClicks();" />

关于javascript - 单击时将值保存在 LocalStorage 中?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22519875/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com