JQuery Cookies Set Expire Time

后端 未结 2 773
忘了有多久
忘了有多久 2020-12-31 07:33

I have this:

if (typeof options.expires == \'number\') {
date = new Date();
date.setTime(date.getTime() + (options.expires * 5 * 1000));
} else {
date = opti         


        
相关标签:
2条回答
  • 2020-12-31 08:00

    10 minutes is 10 * 60 * 1000 milliseconds.

    var date = new Date();
    date.setTime(date.getTime() + (10 * 60 * 1000));
    $.cookie("example", "foo", { expires: date });
    
    0 讨论(0)
  • 2020-12-31 08:02
     var date = new Date();
     var m = 10;
     date.setTime(date.getTime() + (m * 60 * 1000));
     $.cookie("cookie", "value", { expires: date });
    

    Alternatively you could use a function:

    function ExpireCookie(minutes) {
     var date = new Date();
     var m = minutes;
     date.setTime(date.getTime() + (m * 60 * 1000));
     $.cookie("cookie", "value", { expires: date });
    }
    

    Then do ExpireCookie(10);

    0 讨论(0)
提交回复
热议问题