• 博客园logo
  • 会员
  • 众包
  • 新闻
  • 博问
  • 闪存
  • 赞助商
  • HarmonyOS
  • Chat2DB
    • 搜索
      所有博客
    • 搜索
      当前博客
  • 写随笔 我的博客 短消息 简洁模式
    用户头像
    我的博客 我的园子 账号设置 会员中心 简洁模式 ... 退出登录
    注册 登录
南南的空间
博客园    首页    新随笔    联系   管理    订阅  订阅
ASP .NET 三、asp.net+cookie+javascrip制作的购物车

(1)首先,介绍一下javascript操作cookie的基础

//去除空格,回车
String.prototype.Trim = function()
{
    return this.replace(/(^\s*)|(\s*$)/g, ""); 
} 


//设置Cookie
function setCookie(c_name, c_value,expiredays)
{
    var exdate=new Date();
    exdate.setDate(exdate.getDate()+expiredays);

    document.cookie = c_name + "=" + escape(c_value) +
        ((expiredays==null) ? "" : ";expires="+exdate.toGMTString());
}

//按名字读取Cookie
function getCookie(c_name)
{
    if (document.cookie.length>0)
    {
        var m_car=document.cookie.split(';');
        var value=-1;
        for (i = 0; i < m_car.length; i++)
        {
            if(c_name.toString().Trim()==((m_car[i].split('='))[0]).toString().Trim())
            {
                value = (m_car[i].split('='))[1];
            }
            
        }
    }
    return value;
}

 

 

posted on 2012-05-28 17:17  南南的博客  阅读(253)  评论(0)    收藏  举报
刷新页面返回顶部
博客园  ©  2004-2025
浙公网安备 33010602011771号 浙ICP备2021040463号-3