html页面几种存储数据
1.本地存储localstorage-
localStorage 方法存储的数据没有时间限制。第二天、第二周或下一年之后,数据依然可用-
存储方式:-
以键值对(Key-Value)的方式存储,永久存储,永不失效,除非手动删除。-
大小:-
每个域名5M
localStorage.setItem("name","value"); //存值 键name 值 value
var str =localStorage.getItem("name")//根据name取值
console.log(str) //输出结果是value
localStorage.removeItem("name") //清除记录
2.本地存储sessionstorage
HTML5 的本地存储 API 中的 localStorage 与 sessionStorage 在使用方法上是相同的,区别在于 sessionStorage 在关闭页面后即被清空,而 localStorage 则会一直保存。
sessionstorage.setItem("name","value"); //存值 键name 值 value
var str =sessionstorage.getItem("name")//根据name取值
console.log(str) //输出结果是value
sessionstorage.removeItem("name") //清除记录
给指定标签设置元素setAttribute
//给 id为INPUT的标签设置type ="button"
document.getElementById("INPUT").setAttribute("type","button");
获取指定标签的指定元素 getAttribute
//获取id为INPUT标签的id值
document.getElementById("INPUT").getAttribute("id")
使用attr设置元素
$(".class").attr("id","a1")