JS localStorage實(shí)現(xiàn)本地緩存的方法
更新時(shí)間:2013年06月22日 11:25:01 作者:
JS localStorage實(shí)現(xiàn)本地緩存的方法,需要的朋友可以參考一下
復(fù)制代碼 代碼如下:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<title>本地緩存</title>
<script type="text/javascript">
var strKey = "strKey";
var storage = window.localStorage;
function onStart(){
if(storage.getItem(strKey)!=null){
alert(storage.getItem(strKey)+'localStorage');
}else if(Cookie.read(strKey)!=null){
alert(Cookie.read(strKey)+'cookie');
}
}
function bendihuancun(){
var strValue = document.getElementById("username").value;
if (storage) {
storage.setItem(strKey, strValue);
} else {
Cookie.write(strKey, strValue);
}
}
</script>
</head>
<body onload="onStart()">
<input type="text" id="username" value="123">
<input type="button" value="保存緩存" onclick="bendihuancun()">
</body>
</html>
<html>
<head>
<title>本地緩存</title>
<script type="text/javascript">
var strKey = "strKey";
var storage = window.localStorage;
function onStart(){
if(storage.getItem(strKey)!=null){
alert(storage.getItem(strKey)+'localStorage');
}else if(Cookie.read(strKey)!=null){
alert(Cookie.read(strKey)+'cookie');
}
}
function bendihuancun(){
var strValue = document.getElementById("username").value;
if (storage) {
storage.setItem(strKey, strValue);
} else {
Cookie.write(strKey, strValue);
}
}
</script>
</head>
<body onload="onStart()">
<input type="text" id="username" value="123">
<input type="button" value="保存緩存" onclick="bendihuancun()">
</body>
</html>
您可能感興趣的文章:
- JS 中LocalStorage和SessionStorage的使用
- JS中LocalStorage與SessionStorage五種循序漸進(jìn)的使用方法
- 詳解JavaScript中l(wèi)ocalStorage使用要點(diǎn)
- JS實(shí)現(xiàn)本地存儲(chǔ)信息的方法(基于localStorage與userData)
- AngularJS之ionic 框架下實(shí)現(xiàn) Localstorage本地存儲(chǔ)
- 移動(dòng)端使用localStorage緩存Js和css文的方法(web開發(fā))
- JavaScript中l(wèi)ocalStorage對(duì)象存儲(chǔ)方式實(shí)例分析
- JavaScript使用localStorage存儲(chǔ)數(shù)據(jù)
- 使用JS獲取SessionStorage的值
- JS localStorage存儲(chǔ)對(duì)象,sessionStorage存儲(chǔ)數(shù)組對(duì)象操作示例
相關(guān)文章
JavaScript創(chuàng)建一個(gè)object對(duì)象并操作對(duì)象屬性的用法
這篇文章主要介紹了JavaScript創(chuàng)建一個(gè)object對(duì)象并操作對(duì)象屬性的用法,實(shí)例分析了javascript使用object類定義對(duì)象及屬性的用法,需要的朋友可以參考下2015-03-03JavaScript實(shí)現(xiàn)計(jì)算圓周率到小數(shù)點(diǎn)后100位的方法示例
這篇文章主要介紹了JavaScript實(shí)現(xiàn)計(jì)算圓周率到小數(shù)點(diǎn)后100位的方法,簡(jiǎn)單分析了圓周率計(jì)算的原理并結(jié)合實(shí)例形式給出了javascript計(jì)算圓周率的具體操作技巧,需要的朋友可以參考下2018-05-05JS實(shí)現(xiàn)左右拖動(dòng)改變內(nèi)容顯示區(qū)域大小的方法
這篇文章主要介紹了JS實(shí)現(xiàn)左右拖動(dòng)改變內(nèi)容顯示區(qū)域大小的方法,涉及JavaScript實(shí)時(shí)響應(yīng)鼠標(biāo)事件動(dòng)態(tài)改變頁(yè)面元素屬性的技巧,具有一定參考借鑒價(jià)值,需要的朋友可以參考下2015-10-10JavaScript中調(diào)用函數(shù)的4種方式代碼實(shí)例
這篇文章主要介紹了JavaScript中調(diào)用函數(shù)的4種方式代碼實(shí)例,本文分別給出方法調(diào)用模式、函數(shù)調(diào)用模式、構(gòu)造器調(diào)用模式、apply調(diào)用模式4種方式的代碼實(shí)例,需要的朋友可以參考下2015-07-07javascript HTML5 canvas實(shí)現(xiàn)打磚塊游戲
這篇文章主要介紹了基于javascript HTML5 canvas實(shí)現(xiàn)打磚塊游戲的具體實(shí)現(xiàn)代碼,文中示例代碼介紹的非常詳細(xì),具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下2016-04-04escape、encodeURI 和 encodeURIComponent 的區(qū)別
escape(), encodeURI()和encodeURIComponent()是在Javascript中用于編碼字符串的三個(gè)常用的方法,而他們之間的異同卻困擾了很多的Javascript初學(xué)者,今天我就在這里對(duì)這三個(gè)方法詳細(xì)地分析與比較一下。2009-03-03