• // 说明:用 Javascript 操作 Cookie
  • // 整理:http://www.CodeBit.cn
  •  
  • function getCookie( name ) {
  • var start = document.cookie.indexOf( name + "=" );
  • var len = start + name.length + 1;
  • if ( ( !start ) && ( name != document.cookie.substring( 0, name.length ) ) ) {
  • return null;
  • }
  • if ( start == -1 ) return null;
  • var end = document.cookie.indexOf( ';', len );
  • if ( end == -1 ) end = document.cookie.length;
  • return unescape( document.cookie.substring( len, end ) );
  • }
  •  
  • function setCookie( name, value, expires, path, domain, secure ) {
  • var today = new Date();
  • today.setTime( today.getTime() );
  • if ( expires ) {
  • expires = expires * 1000 * 60 * 60 * 24;
  • }
  • var expires_date = new Date( today.getTime() + (expires) );
  • document.cookie = name+'='+escape( value ) +
  • ( ( expires ) ? ';expires='+expires_date.toGMTString() : '' ) + //expires.toGMTString()
  • ( ( path ) ? ';path=' + path : '' ) +
  • ( ( domain ) ? ';domain=' + domain : '' ) +
  • ( ( secure ) ? ';secure' : '' );
  • }
  •  
  • function deleteCookie( name, path, domain ) {
  • if ( getCookie( name ) ) document.cookie = name + '=' +
  • ( ( path ) ? ';path=' + path : '') +
  • ( ( domain ) ? ';domain=' + domain : '' ) +
  • ';expires=Thu, 01-Jan-1970 00:00:01 GMT';
  • }
    TO:作者: Dustin     来源: dustindiaz.com

    相关文章:

    • 2021-05-28
    • 2021-07-03
    猜你喜欢
    • 2022-02-15
    • 2021-11-10
    • 2021-06-21
    • 2021-06-13
    • 2021-06-17
    • 2021-10-22
    • 2021-09-17
    相关资源
    相似解决方案