您的位置:首页 > Web前端 > HTML5

html5本地存储webstorage

2016-05-13 16:05 375 查看
<!DOCTYPE html>

<html xmlns="http://www.w3.org/1999/xhtml">

<head>

    <div>webstorage存储技术</div>

    <title></title>

    <script src="js/jquery-1.10.2.js"></script>

    <script type="text/javascript">

        function MyClick() {

            var userName = $("#txtUserName").val();

            var password = $("#txtPwd").val();

            sessionStorage.setItem("k_userName", userName);

            sessionStorage.setItem("k_password", password);

            //localStorage.setItem("k_userName", userName);

            //localStorage.setItem("k_password", password);

            alert("存储成功");

        }

        function MyClick1() {

            alert(sessionStorage.getItem("k_userName"));
        }

      

        function PostCon() {

            var sCon = $("#trCon").val();

            $("#dCon").append("<div>" + sCon + "</div>");

            localStorage.setItem("k_Con", $("#dCon").html());

        }

        $(function () {

            if (localStorage.getItem("k_Con") != null) {

                "k_Con", $("#dCon").html(localStorage.getItem("k_Con"));

            }

        })

function Clear() {

            $("#dCon").html("");

            localStorage.clear();

        }

    </script>

</head>

<body>

    <div><input type="text" id="txtUserName" /><input type="button" value="确定" onclick="MyClick()"/></div>

    <div><input type="password" id="txtPwd" /><input type="button" value="确定1" onclick="MyClick1()"/></div>
    <!--<div><input type="text" id="username" /><input type="button" value="确定" /></div>-->

    <div><textarea id="trCon"  cols="30" rows="8"></textarea></div>

    <div><input type="button" value="Ok" onclick="PostCon()" /><input type="button" value="cancel" onclick="Clear()"/></div>

    <div id="dCon"></div>

</body>

</html>
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: