js操作cookie

<script language="javascript">
//写入cookie
function setCookie(name,value,expiresDays){
        var d=new Date();
        d.setTime(d.getTime()+expiresDays*24*60*60*1000);
        document.cookie=name+'='+escape(value)+';'+(expiresDays==null?'':d.toGMTString());
    }
//读取cookie
function getCookie(name){
    str_cookie=document.cookie;
    if(str_cookie.length>0){
        start=str_cookie.indexOf(name+'=');
        start+=name.length+1;
        if(start!=-1){
            end=str_cookie.indexOf(';',start);
            if(end==-1){
                end=str_cookie.length;
            }
        }
        return unescape(str_cookie.substring(start,end));
    }
    return '';
}
</script>
posted @ 2010-06-24 13:08  涛光  阅读(322)  评论(0编辑  收藏  举报