码迷,mamicode.com
首页 > Web开发 > 详细

Html5 本地存储 实现刷新页面数据依然存在

时间:2017-04-30 17:16:21      阅读:229      评论:0      收藏:0      [点我收藏+]

标签:type   class   tor   需要   oca   页面   jquery   click   bsp   

1.首先需要引入jquery

2.

<body>
a<input type="text" id="a"><br>
b<input type="text" id="b"><br>
<button onclick="test()">click</button>
<button onclick="c()">clear</button>
<script>
$("input").each(function(){                               //遍历input标签给其赋值
	var key = $(this).attr(‘id‘);
	$(this).val(localStorage.getItem(key));

})

	function test(){
		$("input").each(function(){              //遍历input标签将第一次的值存到localStorage中
			var key = $(this).attr(‘id‘);
			var value = $(this).val();
			localStorage.setItem(key,value);
		
		})
	}
	
	
	function c(){                      //清除本地存储
		localStorage.clear();		
	}
	
</script>
</body>

 

Html5 本地存储 实现刷新页面数据依然存在

标签:type   class   tor   需要   oca   页面   jquery   click   bsp   

原文地址:http://www.cnblogs.com/fydora/p/6789734.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!