學習儲存Localstorage的程式方法
setItem(key, value)
– store key/value pair.getItem(key)
– get the value by key.removeItem(key)
– remove the key with its value.clear()
– delete everything.key(index)
– get the key on a given position.length
– the number of stored items.
資料可以儲存成字串對應到數值
例如:
localStorage.setItem('text', text.value);
則會將資料儲存成key是text,值是text.value。
也可以儲存成陣列array的格式
HTML
See the Pen
JavaScript – store Localstorage by G-Dee (@G-Dee)
on CodePen.
CSS
See the Pen
JavaScript – store Localstorage by G-Dee (@G-Dee)
on CodePen.
JS
See the Pen
JavaScript – store Localstorage by G-Dee (@G-Dee)
on CodePen.
參考資料:
留言