手机
当前位置:查字典教程网 >编程开发 >Javascript教程 >JS localStorage实现本地缓存的方法
JS localStorage实现本地缓存的方法
摘要:复制代码代码如下:本地缓存varstrKey="strKey";varstorage=window.localStorage;functio...

复制代码 代码如下:<!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="保存缓存">

</body>

</html>

【JS localStorage实现本地缓存的方法】相关文章:

jQuery实现html表格动态添加新行的方法

JavaScript实现文本框中默认显示背景图片在获得焦点后消失的方法

jquery实现图片左右切换的方法

JS实现屏蔽shift,Ctrl,alt等功能键的方法

JS实现定时自动关闭DIV层提示框的方法

jQuery仿gmail实现fixed布局的方法

js+html5操作sqlite数据库的方法

jQuery实现限制textarea文本框输入字符数量的方法

JS实现带缓冲效果打开、关闭、移动一个层的方法

JQuery实现动态添加删除评论的方法

精品推荐
分类导航