首页 > localStorage存储总是出现undefined,求解

localStorage存储总是出现undefined,求解



<script> function set(Key) { localStorage.setItem(Key, "demo"); } function get(Key){ localStorage.getItem(Key); } </script>

上边是我的代码,但是我在输入set(1)的时候总是伴随undefined,但是却存入了,get(1)的时候也是一样出现undefined,但是取不到值,只有输入localStorage.getItem(1)的时候才能取到,有人知道为什么吗?求帮助


你函数没返回值当然是undefined

function set(Key) {
        return localStorage.setItem(Key, "demo");
    }

    function get(Key){
        return localStorage.getItem(Key);
    }
【热门文章】
【热门文章】