I want to save the range input slider's discharge (the last position on the slider) in session storage and let the last release value appear when the web page is refreshed. I don't know exactly because I just started.
I googled and found out what to do with json.stringfy.Can you tell me? Is there anyone who has it?
javascript html css
https://developer.mozilla.org/en-US/docs/Web/API/Window/sessionStorage
sessionStorage is written like this:
sessionStorage.setItem('key', 'value');
let a = sessionStorage.getItem('key');
console.log(a); // value
If the value you want to put in is not a string but an object type, write JSON.stringify()
to create a string, save it, and return it to the object when ejecting:
let obj = { a: 1, b: 2 };
sessionStorage.setItem('foo', JSON.stringify(obj));
let obj2 = JSON.parse(sessionStorage.getItem('foo'));
console.log(obj2); // Object { a: 1, b: 2 }
I can use this to save the range input slider's value and take it out, right?
© 2024 OneMinuteCode. All rights reserved.