localStorage 只在同一域名下,才有效

    1. window.addEventListener('storage',function(){
    2. }) //缓存发生改变时触发,在同一个窗口,不同的页面触发有效
    //01.html 
    <body>
        <input type="text" id="st">
        <script>
            var st = document.getElementById("st");
    
            st.onblur = function () {
    
                localStorage.setItem("name", st.value);
            }
            window.addEventListener("storage",function(){
                console.log("ok");
            })
        </script>
    </body>
    
    //02.html 
    <body>
        <input type="text" id="st">
        <script>
            var st = document.getElementById("st");
            window.addEventListener("storage",function(event){
                console.log(event);
                st.value = event.newValue;
            })
        </script>
    </body>