• JSONCookie 操作


    需要使用jquery.jsoncookie.js

               jquery.cookie.js

    var COOKIE_NAME = "Bind_Prod_List";
    var product;
     product = $.JSONCookie(COOKIE_NAME);
    
    
    //判断是否存在
    function IsExistsInCookie(userName) {
        var flag = false;
        for (var i = 0; i < product.Product.length; i++) {
            var p = product.Product[i];
            if (p.UserName == userName ) {//存在
                flag = true;
                break;
            }
        }
        return flag;
    }
    //获取cookie
    function GetCookie(uid) {
        if (product.Product) {
            for (var i = 0; i < product.Product.length; i++) {
                var p = product.Product[i];
                if (p.Uid == uid || p.UserName == uid) {
                    return p;
                    break;
                }
            }
        }
    }
    //写入cookie
    function SetCookie(userName, password, type, uid, group, pid) {
        if (typeof (product.Product) == "undefined") {
            product = { "Product": [{ "UserName": "" + userName + "", "PassWord": "" + password + "", "Type": "" + type + "", "Uid": "" + uid + "", "Group": "" + group + "", "Pid": "" + pid + ""}] };
            $.JSONCookie(COOKIE_NAME, product, { path: '/', expires: timeOut });
            if (ex == "1")
                GetUserStockList(userName, password, type, uid, group, pid);
        } else {
            if (!IsExistsInCookie(userName, password, type, uid)) {
                var json = { "UserName": "" + userName + "", "PassWord": "" + password + "", "Type": "" + type + "", "Uid": "" + uid + "", "Group": "" + group + "", "Pid": "" + pid + "" };
                product.Product.push(json); //添加
                $.JSONCookie(COOKIE_NAME, product, { path: '/', expires: timeOut });
            } 
        }
        ShowList();   
    }
    
    //显示列表
    function ShowList() {
        var html = "";
        var typeName = "";
        var src = "";
        if (product.Product) {
            $.each(product.Product, function (index, prod) {
                switch (prod.Type) {
                   
                }
                html += "<li><img src='" + src + "' />&nbsp;" + typeName + ":<a href='javascript:void(0)' onclick=\"GetUserStockList('" + prod.UserName + "','" + prod.PassWord + "','" + prod.Type + "','" + prod.Uid + "','" + prod.Group + "','" + prod.Pid + "')\">" + prod.UserName + "</a></li>"
            });
        }
        html += productHtml;
        $("#content").html(html);
    }
  • 相关阅读:
    随机出题问题
    简读《构建之法》提问
    大二下第一次课后作业
    大道至简第七第八章读后感
    继承与接口动手动脑
    大道至简第六章读后感
    数组里的随机数问题
    大道至简第五章读后感
    输入法的用户界面
    搜索水王
  • 原文地址:https://www.cnblogs.com/xffy1028/p/2442657.html
Copyright © 2020-2023  润新知