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

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

javascript实现模拟时钟的方法

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

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

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

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

javascript用函数实现对象的方法

javascript实现Table排序的方法

jQuery实现返回顶部效果的方法

JavaScript实现弹出模态窗体并接受传值的方法

精品推荐
分类导航