<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title></title>
</head>
<body>
<input type="button" value="保存" />
<input type="button" value="获取" />
<input type="button" value="删除" />
<input type="button" value="清空所有" />
<input type="text" value="" />
<script type="text/javascript">
//sessionStorage 浏览器关闭时,sessionStorage没有,不能跨页面
window.onload = function () {
var aInput = document.getElementsByTagName('input');
//保存sessionstorage
aInput[0].onclick = function () {
var text = aInput[4].value;
// 保存
window.sessionStorage.setItem('one', text);
window.sessionStorage.setItem('two', text);
}
//获取sessionstorage
aInput[1].onclick = function () {
console.log(window.sessionStorage.getItem('one'));
}
//删除sessionstorage
aInput[2].onclick = function () {
window.sessionStorage.removeItem('one');
}
//清除sessionstorage
aInput[3].onclick = function () {
//清除所有sessionstorage数据
window.sessionStorage.clear();
}
}
</script>
</body>
</html>