jqury关于cooke的操作写入cookie后只显示一次的DIV提示框代码

 有时候当用户登录系统后,需要给用户弹出提示框,但是不需要总是弹出来,在这里加入访问cookie来判断是否弹出过提示框,如果弹出过那么保存cookie,下次根据cookie是否存在来判断是否弹出

 

<script type="text/javascript">
function cookiesave(n, v, mins, dn, path){
    if(n)
    {
        
        if(!mins) mins = 365 * 24 * 60;
        if(!path) path = "/";
        var date = new Date();
        
        date.setTime(date.getTime() + (mins * 60 * 1000));
        
        var expires = "; expires=" + date.toGMTString();
        
        if(dn) dn = "domain=" + dn + "; ";
        document.cookie = n + "=" + v + expires + "; " + dn + "path=" + path;
    }
}
function cookieget(n){
    var name = n + "=";
    var ca = document.cookie.split(';');
    for(var i=0;i<ca.length;i++) {
        var c = ca[i];
        while (c.charAt(0)==' ') c = c.substring(1,c.length);
        if (c.indexOf(name) == 0) return c.substring(name.length,c.length);
    }
    return "";
}
function closeclick(){
    document.getElementById('note').style.display='none';
    cookiesave('closeclick','closeclick','','','');
}
function clickclose(){
    if(cookieget('closeclick')=='closeclick'){
        document.getElementById('note').style.display='none';
    }else{
        document.getElementById('note').style.display='block';
    }
}
window.onload=clickclose;
</script>
posted @ 2014-07-23 15:04  程序员徐坤  阅读(532)  评论(0编辑  收藏  举报