Javascript 学习在JS中使用localstorage

Javascript 学习在JS中使用localstorage,javascript,local-storage,Javascript,Local Storage,嘿 我想保存并显示一个名为“bestScore”的值 我在互联网上看到的例子与我的情况相去甚远 我想知道如何存储和显示值 如果有人有一个非常简单的例子 谢谢你你试过在网上查这个吗?有许多关于localStorage的教程可以很容易地找到。localStorage.getItem()和localStorage.setItem()。我怀疑您找不到示例来演示LocalStorage的绝对基础,请参见链接重复参考。 //store the value localStorage.setItem("

我想保存并显示一个名为“bestScore”的值

我在互联网上看到的例子与我的情况相去甚远

我想知道如何存储和显示值

如果有人有一个非常简单的例子


谢谢你

你试过在网上查这个吗?有许多关于localStorage的教程可以很容易地找到。
localStorage.getItem()
localStorage.setItem()
。我怀疑您找不到示例来演示
LocalStorage
的绝对基础,请参见链接重复参考。
//store the value
localStorage.setItem("bestScore", 'here put the score');

//get the value
localStorage.getItem("bestScore");

//you can write it as a function
function saveScore(score){
 localStorage.setItem("bestScore", score);
}

function getScore(scoreName){
 localStorage.getItem(scoreName);
}

//then you can call the function and pass arguments for example
let scoreElement = document.getElementById('score').innerText
saveScore(scoreElement) //call the save function and pass the score to save

scoreElement = getScore('bestScore') //call the get score function and pass the name of the item in the storage