Html5 本地存儲 實現刷新頁面數據依然存在


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>

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM