<meta charset="UTF-8">
<meta name="viewport" content="width=device - width, initial - scale=1.0" & gt;
<body>
Name:
Age:
<script>
//add data
Document. The getElementById (' sessionStorageId '). The onclick=function () {
//get the value of the name and age fields
Var username=document. GetElementById (" username "). The value;
Var age=document. GetElementById (" age "). The value;
//define a user formation is used to store the information
Var user={
Username: the username,
Age: the age
}
//use the stringify () will be a JSON object serialization and deposit to the sessionStorage
Window. The sessionStorage. SetItem (' user 'JSON. Stringify (user));
}
Document. The getElementById (' getsessionStorageId '). The onclick=function () {
Var value=https://bbs.csdn.net/topics/window.sessionStorage.getItem (" user ");
Alert (value);
}
//remove all data
Document. The getElementById (' clearsessionStorageId '). The onclick=function () {
Window. The sessionStorage. The clear ();
}
</script>