localStorage使用总结

转载:https://www.cnblogs.com/st-leslie/p/5617130.html

总结的非常好!

自己的demo

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>本地储存</title>
</head>
<body>
    <p id="dd"></p>
    <script>
        localStorage.setItem("name","小红红");
        localStorage.setItem("age","20");
        localStorage.setItem("height","160cm");

        localStorage.setItem("name","aaaa");   //重新设置name的值,覆盖掉之前的
        localStorage.removeItem("height");   //删除height的值
        var ss = localStorage.getItem("age");
        var dds =document.getElementById("dd");
        dds.innerHTML = ss;     //赋值
        localStorage.clear();  //清除本地储存
    </script>
</body>
</html>

 

posted @ 2018-10-19 10:08  quitpoison  阅读(144)  评论(0编辑  收藏  举报