JS localStorage實現(xiàn)本地緩存的方法
更新時間:2013年06月22日 11:25:01 作者:
JS localStorage實現(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五種循序漸進的使用方法
- 詳解JavaScript中l(wèi)ocalStorage使用要點
- JS實現(xiàn)本地存儲信息的方法(基于localStorage與userData)
- AngularJS之ionic 框架下實現(xiàn) Localstorage本地存儲
- 移動端使用localStorage緩存Js和css文的方法(web開發(fā))
- JavaScript中l(wèi)ocalStorage對象存儲方式實例分析
- JavaScript使用localStorage存儲數(shù)據(jù)
- 使用JS獲取SessionStorage的值
- JS localStorage存儲對象,sessionStorage存儲數(shù)組對象操作示例
相關(guān)文章
把json格式的字符串轉(zhuǎn)換成javascript對象或數(shù)組的方法總結(jié)
下面小編就為大家?guī)硪黄裫son格式的字符串轉(zhuǎn)換成javascript對象或數(shù)組的方法總結(jié)。小編覺得挺不錯的,現(xiàn)在就分享給大家,也給大家做個參考。一起跟隨小編過來看看吧2016-11-11
JS如何設(shè)置滾動屬性默認(rèn)自動滾動到底部(overflow:scroll;)
這篇文章主要給大家介紹了關(guān)于JS如何設(shè)置滾動屬性默認(rèn)自動滾動到底部(overflow:scroll;)的相關(guān)資料,通過本文介紹的的JavaScript代碼示例,你可以實現(xiàn)滾動條默認(rèn)在最底部的效果,需要的朋友可以參考下2023-10-10
BootStrap智能表單實戰(zhàn)系列(七)驗證的支持
這篇文章主要介紹了BootStrap智能表單實戰(zhàn)系列(七)驗證的支持 ,凡是涉及到用戶編輯信息然后保存的頁面,都涉及到一個數(shù)據(jù)是否符合要求的檢查,需要客服端和服務(wù)器端的校驗的問題,本文介紹非常詳細(xì),具有參考價值,需要的朋友可以參考下2016-06-06
學(xué)習(xí)JavaScript設(shè)計模式(鏈?zhǔn)秸{(diào)用)
這篇文章主要帶領(lǐng)大家學(xué)習(xí)JavaScript設(shè)計模式,其中重點介紹鏈?zhǔn)秸{(diào)用,感興趣的小伙伴們可以參考一下2015-11-11

