Created
September 7, 2010 14:27
-
-
Save crossai-2033/568424 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<script> | |
/*利且window.name来做缓存库,缓存天气及新闻 最终存成的window.name格式为 key1@=val1@@127545353@;key2@=val2@@127889999@;*/ | |
var Cache = (function() { | |
var cache = { | |
$: function(x) { return new RegExp('\\b' + x + '@=(.*?)(?=$|@;)') }, | |
get: function(x) { this.$(x).test(window.name); return (RegExp.$1 && RegExp.$1.split('@@')[0]) || null }, | |
set: function(x, val) { | |
var $ = window, __ = this.$(x), value= x + '@=' + val + '@@' + (+ new Date()); | |
__.test($.name) ? ($.name = $.name.replace(__, value), 1) : ($.name += value + '@;') | |
}, | |
del: function(x) { | |
var $ = window, __ = this.$(x); | |
__.test($.name) && ($.name = $.name.replace(__, '').replace(/(@;)+(?!\w)/g, '$1')); | |
}, | |
getCacheTime : function(x){ | |
this.$(x).test(window.name); return (RegExp.$1 && RegExp.$1.split('@@')[1]) || null | |
}, | |
clear: function() { window.name = '' } | |
}; | |
if (!cache.get('domain') || cache.get('domain') != location.href) { | |
cache.clear(); | |
cache.set('domain', location.href); | |
} | |
return cache; | |
})(); | |
var ye=1; | |
window.onload = function() { | |
if (Cache.get('count') === null) { | |
Cache.set('count', ye); | |
Cache.set('haha', 'a' + ye); | |
} else { | |
ye = (Cache.get('count') - 0) + 1; | |
Cache.set('count', ye); | |
Cache.set('haha', 'a' + ye); | |
} | |
aa.innerHTML = Cache.get('count') + ' | ' + Cache.get('haha'); | |
} | |
</script> | |
<span id=aa></span> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment