zoukankan      html  css  js  c++  java
  • 原生js--userData

    userData是IE5及其以上浏览器支持的一种客户端存储方式,它通过在document元素后面附加一个专属的元素来实现。

    对userData的封装:

    /**
     * IE userdata封装
     */
    function UserDataStorage( maxage ){
        var memory = document.createElement( "div" );
        memory.style.display = "none";
        memory.style.behavior = "url('#default#userData')";
        document.body.appendChild( memory );

        if( maxage ){
            var now = new Date().getTime();
            var expires = now + maxage * 1000;
            memory.expires = new Date( expires ).toUTCString();
        }

        memory.load( "UserDataStorage" );

        this.getItem = function( key ){
            return memory.getAttribute( key ) || null;
        }
        this.setItem = function( key, value ){
            memory.setAttribute( key, value );
            memory.save( "UserDataStorage" );
        }
        this.removeItem = function( key ){
            memory.removeAttribute( key );
            memory.save( "UserDataStorage" );
        }
    }

  • 相关阅读:
    迷宫
    【NOIP2001普及组】最大公约数和最小公倍数问题
    latex online tool
    连续自然数和
    又是毕业季Ⅰ
    区间素数
    【AHOI2005】约数研究
    【NOIP2011提高组】计算系数
    【NOIP2012普及组】寻宝
    plsql 导出oracle数据库
  • 原文地址:https://www.cnblogs.com/charling/p/3591054.html
Copyright © 2011-2022 走看看