JS localStorage实现本地缓存的方法
更新时间:2013年06月22日 11:25:01 作者:
JS localStorage实现本地缓存的方法,需要的朋友可以参考一下
复制代码 代码如下:
<!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中localStorage使用要点
- JS实现本地存储信息的方法(基于localStorage与userData)
- AngularJS之ionic 框架下实现 Localstorage本地存储
- 移动端使用localStorage缓存Js和css文的方法(web开发)
- JavaScript中localStorage对象存储方式实例分析
- JavaScript使用localStorage存储数据
- 使用JS获取SessionStorage的值
- JS localStorage存储对象,sessionStorage存储数组对象操作示例
相关文章
把json格式的字符串转换成javascript对象或数组的方法总结
下面小编就为大家带来一篇把json格式的字符串转换成javascript对象或数组的方法总结。小编觉得挺不错的,现在就分享给大家,也给大家做个参考。一起跟随小编过来看看吧2016-11-11
JS如何设置滚动属性默认自动滚动到底部(overflow:scroll;)
这篇文章主要给大家介绍了关于JS如何设置滚动属性默认自动滚动到底部(overflow:scroll;)的相关资料,通过本文介绍的的JavaScript代码示例,你可以实现滚动条默认在最底部的效果,需要的朋友可以参考下2023-10-10


最新评论