付费节点推荐
免费节点
节点使用教程
时间:2015年3月29日
地点:甲由传媒(实习)
sessionStorage Demo
数据存储在session,关闭浏览器或等到session timeout都可以清除数据
function saveStorage(id){
var target = document.getElementById(id);
var str= target.value;
sessionStorage.setItem("message",str);
}
function loadStorage(id){
var target =document.getElementById(id);
var msg = sessionStorage.getItem("message");
target.innerHTML = msg;
}
lcoalStorage Demo
localStorage里存储的数据会保存在本地,需清除cookies才能完全删除。
function saveStorage(id){
var target = document.getElementById(id);
var str = target.value;
localStorage.setItem("message",str);
}
function loadStorage(id){
var target = document.getElementById(id);
var msg = localStorage.getItem("message");
target.innerHTML = msg;
}
web Storage制作留言Demo
function saveStorage(id){
var data = document.getElementById(id).value;
var time = new Date().getTime();
localStorage.setItem(time,data);
alert("数据以存储");
loadStorage('msg');
}
function loadStorage(id){
var result = "
" +value+ " | "+date+" |
";
var target =document.getElementById(id);
target.innerHTML = result;
}
function clearStorage(){
localStorage.clear();
alert("数据已删除");
loadStorage('msg');
}
localStorage 简单数据库
姓名: | |
Email: | |
电话号码: | |
备注: | |
检索:
function saveStorage(){
var data = new Object;
data.name=document.getElementById("name").value;
data.email=document.getElementById("email").value;
data.tel=document.getElementById("tel").value;
data.memo=document.getElementById("memo").value;
var str = JSON.stringify(data); //Object,数组 -> json str,可参考此文档
localStorage.setItem(data.name,str);
alert("数据已保存");
}
function findStorage(id){
var find = document.getElementById('find').value;
var str = localStorage.getItem(find);
var data = JSON.parse(str); //将json str -> Obj,可参考此文档
var result ="姓名:"+data.name +"
";
result +="Email:"+data.email +"
";
result +="电话:"+data.tel +"
";
result +="备注:"+data.memo +"
";
var target = document.getElementById(id);
target.innerHTML = result;
未经允许不得转载:Bcoder资源网 » HTML5 Web Storage
评论前必须登录!
登陆 注册