怎样找人做网站,网络服务平台有哪些,合肥经开区建设局网站,培训网址蛮讨厌IE的#xff0c;因为他常常需要特别照顾#xff0c;就像DOM Storage(sessionStorage和localStorage)只能支持IE8#xff0c;对于以下的只能使用userData。 原理#xff1a;通过在document元素后面附加一个专属的“DHTML行为”来实现客户端存储#xff0c; var memor…蛮讨厌IE的因为他常常需要特别照顾就像DOM Storage(sessionStorage和localStorage)只能支持IE8对于以下的只能使用userData。 原理通过在document元素后面附加一个专属的“DHTML行为”来实现客户端存储 var memorydocument.createElement(div);//创建一个元素memory.style.displaynone;//将其隐藏memory.style.behaviorurl(#default#userData); //附加userData行为document.body.appendChild(memory);//将其添加到document元素中 一旦给元素赋予了“userData”行为该元素就拥有了load()和save()方法load()方法用于载入存储的数据。使用它的时候必须传递一个字符串作为参数——类似于一个文件名该参数用来指定要载入的存储数据。当数据载入的时候就可以通过该元素的属性来访问这些名值对形式的数据。 可以使用getAttribute()来查询这些数据通过setAttribute()方法设置属性然后调用save()方法可以存储性的数据而要删除数据通过使用removeAttribute()方法然后调用save()方法即可。 IE userData BehaviorMethodsDescriptiongetAttribute(attr)获取存储对象中属性值load(name)载入存储数据对象removeAttribute(attr)删除存储对象中的属性save(name)更新存储数据对象setAttribute(attr, value)设置存储对象中的键对值properties expires数据的有效期XMLDocumentReturns a reference to the XML Document of the persisted object.基于userData实现部分存储API /*基于IE的userData实现只有在IE中有效,保存名为UserDataStorage.js*/function UserDataStorage(maxage){//创建一个document元素鼻骨附加userData行为//因此该元素得save()和loda方法var memorydocument.createElement(div);memory.style.displaynone;memory.style.behaviorurl(#default#userData); //附加userData行为document.body.appendChild(memory);//如果传递了maxage参数单位为秒则将其设置为userData的有效期以毫秒为单位if(maxage){var nownew Date().getTime(); //当前时间var expiresnowmaxage*1000;//当前时间加上有效期就等于过期时间memory.expiresnew Date(expires).toUTCString(); //设置userData的过期时间}//通过载入存储的数据初始化memory元素//参数是任意的只要是在保存的时候存在的就可以了memory.load(UserDataStorage); //载入存储数据this.getItemfunction(key){ //通过属性来获取保存的值return memory.getAttribute(key) || null;};this.setItemfunction(key,value){memory.setAttribute(key,value); //已设置属性的形式来保存数据memory.save(UserDataStorage); //保存数据改变后的状态};this.removeItemfunction(key){memory.removeAttribute(key); //删除存储的数据memory.save(UserDataStorage); //再次保存状态}} 因为以上只能针对ie所以要在最后写上 !--[if IE]script srcUserDataStorage.js/script![endif]-- userData允许存储的数据量比cookie大但是却比localStorage以及sessionStorage允许存储的数据量要小。转载于:https://www.cnblogs.com/RachelChen/p/5435086.html