【Go 语言社区】 HTML5 前端--数据保存实例

时间:2022-05-04
本文章向大家介绍【Go 语言社区】 HTML5 前端--数据保存实例,主要内容包括其使用实例、应用技巧、基本知识点总结和需要注意事项,具有一定的参考价值,需要的朋友可以参考一下。

保存数据--->到本地s.html:

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
        <meta charset="UTF-8">
    <!--
            作者:1528884535@qq.com
            时间: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>