您的位置:首页 > 编程语言 > ASP

asp.net+cookie+javascrip制作的购物车基础知识

2012-06-13 09:25 330 查看
首先,介绍一下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;

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