手机
当前位置:查字典教程网 >编程开发 >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实现本地缓存的方法】相关文章:

javascript实现table表格隔行变色的方法

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

js实现一个链接打开两个链接地址的方法

javascript用函数实现对象的方法

JQuery+CSS实现图片上放置按钮的方法

Javascript实现每日自动换一张图片的方法

JavaScript实现鼠标点击后层展开效果的方法

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

JavaScript实现斗地主游戏的思路

JavaScript检查子字符串是否在字符串中的方法

精品推荐
分类导航