<h1>sessionStorage</h1>
<input type="text" id="testValue" placeholder="請輸入要儲存的值"></input>
<button onclick="doSave();">儲存</button>
<button onclick="doGet();">取得</button>
<button onclick="doRemove();">移除</button>
function getTestValue(){ 
    return window.sessionStorage.getItem("test");
}
function setTestValue(value){
 window.sessionStorage.setItem("test",value);
}
function removeTestValue(){
    window.sessionStorage.removeItem("test");
}

function doSave(){
  setTestValue($('#testValue').val());
}
function doGet(){
  alert(getTestValue());
}
function doRemove(){
  removeTestValue();
}

External CSS

This Pen doesn't use any external CSS resources.

External JavaScript

  1. //cdnjs.cloudflare.com/ajax/libs/jquery/2.1.3/jquery.min.js