`
hzjmllp686
  • 浏览: 1480 次
  • 性别: Icon_minigender_1
  • 来自: 重庆
最近访客 更多访客>>
社区版块
存档分类
最新评论

本地存储 LocalStorage

阅读更多
<html>
<body>

<form id="myForm">
Firstname: <input id="fname" type="text" value="Mickey" />
Lastname: <input id="lname" type="text" value="Mouse" />
<input id="sub" type="button" value="Submit" />
</form>

<p>Get the value of all the elements in the form:<br />
<script type="text/javascript">
var x=document.getElementById("myForm");
var len = x["length"];

alert(typeof(window.localStorage));

localStorage.a = 3;//设置a为"3"
localStorage["a"] = "sfsf";//设置a为"sfsf",覆盖上面的值
localStorage.setItem("b","isaac");//设置b为"isaac"
var a1 = localStorage["a"];//获取a的值
var a2 = localStorage.a;//获取a的值
var b = localStorage.getItem("b");//获取b的值
localStorage.removeItem("c");//清除c的值

alert(window.localStorage.getItem("b"))
for (var i=0;i<x.length;)
  {
  
          x.removeChild(x.elements[i])
  }

</script>
</p>

</body>
</html>
分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics