<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
</head>
<body>

</body>
<script>

    var test = localStorage.getItem("test");
    if(test && test!=null){
        alert("已经有缓存"+test);
    }else{
        var test = localStorage.setItem("test","123");
        alert("没有缓存，已插入新缓存"+test);
    }
</script>
</html>