1. 程式人生 > 其它 >【Go 語言社群】 HTML5 前端--資料儲存例項

【Go 語言社群】 HTML5 前端--資料儲存例項

儲存資料--->到本地s.html:

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
        <meta charset="UTF-8">
    <!--
            作者:[email protected]
            時間:2016-01-29
            描述:資料的快取的資料操作,應用的方式和方法
    -->
    <title>本地快取</title>
    <script type="text/javascript">
        //  相當於與redis 去儲存的資料的資訊方式。主要的測試的資料更新
        var strKey = "strKey";
        var storage = window.localStorage;
        var Cookie;
        function onStart(){
            if(storage.getItem(strKey)!=null){
                alert(storage.getItem(strKey)+'localStorage');
                window.location="ww.html";
            }else if(Cookie.read(strKey)!=null){
                alert(Cookie.read(strKey)+'cookie');
            }
        }
        // 儲存的資料的操作的,資料的儲存到餓餓擦做的餓
        function bendihuancun() {
            alert("test data update !!! ");
            var strValue = document.getElementById("username").value;
            if (storage) {
                storage.setItem(strKey, strValue);
            } else {
                Cookie.write(strKey, strValue);
            }
            onStart();
        }
    </script>
</head>
<body >
<input type="text" id="username" value="123">
<input type="button" value="儲存快取" onclick="bendihuancun()">
</body>
</html>
獲取本地資料---->
<html>
<head>
<meta charset="UTF-8">
    <script>
        document.domain = "localhost";
        function aa(){
            alert("p");
        }
    </script>
</head>
<body>
<iframe src="http://localhost/DIS/s.html" id="i">
</iframe>
<script>
    var storage = window.localStorage;
    // 後去資料,到資料本地的操作的資料;
    // 資料的儲存的方式
    alert(storage.getItem("strKey")+'localStorage');
    document.getElementById('i').onload = function(){
        var d = document.getElementById('i').contentWindow;
        var a=d.a();
        console.log(a);
    };
</script>
</body>
</html>