业精于勤而荒于嬉 行成于思而毁于随
Javascript读写Cookies
[ 2006/10/29 23:33 | by ipaddr ]
[code]
<script type="text/javascript">
// 写 cookie
function setCookie(sName, sValue, iTime)
{
var date = new Date();
date.setTime(date.getTime()+iTime*1000);
document.cookie = escape(sName) + "=" + escape(sValue) + "; expires=" + date.toGMTString();
}
// 读 cookie
function getCookie(sName)
{
var aCookie = document.cookie.split("; ");
for (var i=0; i < aCookie.length; i++)
{
var aCrumb = aCookie[i].split("=");
if (escape(sName) == aCrumb[0])
return unescape(aCrumb[1]);
}
return null;
}
// 删 cookie
function delCookie(sName){
var date = new Date();
document.cookie = sName + "= ; expires=" + date.toGMTString();
}
// 测试函数
function trace(){
alert(document.cookie);
}
</script>
[/code]>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
<script type="text/javascript">
// 写 cookie
function setCookie(sName, sValue, iTime)
{
var date = new Date();
date.setTime(date.getTime()+iTime*1000);
document.cookie = escape(sName) + "=" + escape(sValue) + "; expires=" + date.toGMTString();
}
// 读 cookie
function getCookie(sName)
{
var aCookie = document.cookie.split("; ");
for (var i=0; i < aCookie.length; i++)
{
var aCrumb = aCookie[i].split("=");
if (escape(sName) == aCrumb[0])
return unescape(aCrumb[1]);
}
return null;
}
// 删 cookie
function delCookie(sName){
var date = new Date();
document.cookie = sName + "= ; expires=" + date.toGMTString();
}
// 测试函数
function trace(){
alert(document.cookie);
}
</script>
[/code]>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>