代码示例:(标识:jsck_storage_getitem)
<!DOCTYPE html>
<html>
<body>

<h1>Storage getItem() 方法</h1>

<p>本例演示如何使用 getItem() 方法获取指定的本地存储项的值。</p>

<h2>缺少 localStorage 项目?</h2>

<p>由于您的本地存储中可能没有存储指定的项目,因此我们添加了一个脚本来为您创建它。</p>

<button onclick="createItem()">创建本地存储项</button>

<h2>获取名为 "mytime" 的本地存储项的值</h2>

<p>单击按钮获取项目值:</p>

<button onclick="myFunction()">获取项目值</button>

<p id="demo"></p>

<script>

function createItem() {
  localStorage.mytime = Date.now();
}

function myFunction() {
  var x = localStorage.getItem("mytime");
  document.getElementById("demo").innerHTML = x;
}

</script>
</body>
</html>
运行结果: