jquery设置cookie过期时间为10秒钟

兼容性IE8+

expires的值不能设置为小数,因为除了chrome,其他浏览器都不支持小数,所以我们必须使用setTime()来设置具体日期

jquery方法:

var date = new Date();
date.setTime(date.getTime()+10*1000);//只能这么写,10表示10秒钟
$.cookie('loginCount', ++loginCount, {expires: date});

js方法:

document.cookie='loginCount=1;expires='+new Date()+';path=/';

猜你喜欢

转载自blog.csdn.net/abc2575/article/details/80874140
今日推荐