JQuery操作Cookie

写入Cookie:

第一步引用文件(c顺序不能颠倒):

<script src="js/jquery-1.4.2-vsdoc-cn.js" type="text/javascript"></script>
<script src="js/cookies.jquery.js" type="text/javascript"></script>

第二步写JQuery,设置Cookie

<script type="text/javascript">
        $(function () {
            $("#btnLogin").click(function () {
                var strName = $("#txtName").val();
                var strPwd = $("#txtPwd").val();
                $.cookie("un", strName, { expires: 1 });
                $.cookie("up", strPwd, { expires: 1 });
                window.location = "Cookies1.htm";//跳转到的页面
            });
        })
    </script>

读取Cookie的操作

第一步:引用文件(和上边的引用一样)。

第二步:读取Cookie。

<script type="text/javascript">
$(function () {
$("#txtName").text($.cookie("un"));
$("#txtPwd").text($.cookie("up"));
})
</script>

以后的两个文件从网上都能找到下载下来。在此我就不提供了。

原文地址:https://www.cnblogs.com/shinelhui/p/3011688.html