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)本地存儲信息的方法(基于localStorage與userData)
- AngularJS之ionic 框架下實(shí)現(xiàn) Localstorage本地存儲
- 移動端使用localStorage緩存Js和css文的方法(web開發(fā))
- JavaScript中l(wèi)ocalStorage對象存儲方式實(shí)例分析
- 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)在就分享給大家,也給大家做個(gè)參考。一起跟隨小編過來看看吧2016-11-11
js項(xiàng)目中前端如何實(shí)現(xiàn)無感刷新token
本文主要介紹了js項(xiàng)目中前端如何實(shí)現(xiàn)無感刷新token,文中通過示例代碼介紹的非常詳細(xì),對大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來一起學(xué)習(xí)學(xué)習(xí)吧2023-07-07
JS如何設(shè)置滾動屬性默認(rèn)自動滾動到底部(overflow:scroll;)
這篇文章主要給大家介紹了關(guān)于JS如何設(shè)置滾動屬性默認(rèn)自動滾動到底部(overflow:scroll;)的相關(guān)資料,通過本文介紹的的JavaScript代碼示例,你可以實(shí)現(xiàn)滾動條默認(rèn)在最底部的效果,需要的朋友可以參考下2023-10-10
BootStrap智能表單實(shí)戰(zhàn)系列(七)驗(yàn)證的支持
這篇文章主要介紹了BootStrap智能表單實(shí)戰(zhàn)系列(七)驗(yàn)證的支持 ,凡是涉及到用戶編輯信息然后保存的頁面,都涉及到一個(gè)數(shù)據(jù)是否符合要求的檢查,需要客服端和服務(wù)器端的校驗(yàn)的問題,本文介紹非常詳細(xì),具有參考價(jià)值,需要的朋友可以參考下2016-06-06
學(xué)習(xí)JavaScript設(shè)計(jì)模式(鏈?zhǔn)秸{(diào)用)
這篇文章主要帶領(lǐng)大家學(xué)習(xí)JavaScript設(shè)計(jì)模式,其中重點(diǎn)介紹鏈?zhǔn)秸{(diào)用,感興趣的小伙伴們可以參考一下2015-11-11

