Cov txheej txheem:

LocalStorage getItem yog dab tsi?
LocalStorage getItem yog dab tsi?

Video: LocalStorage getItem yog dab tsi?

Video: LocalStorage getItem yog dab tsi?
Video: Учебник по JavaScript LocalStorage — пример setItem(), getItem(), removeItem(), clear() и key() 2024, Kaum ib hlis
Anonim

getItem () Cov getItem () txoj kev tso cai rau koj nkag mus rau cov ntaub ntawv khaws cia hauv qhov browser localStorage khoom. Nws lees txais tsuas yog ib qho parameter uas yog tus yuam sij thiab rov qab tus nqi raws li txoj hlua.

Yog li ntawd, kuv yuav ua li cas thiaj li tau txais cov khoom los ntawm localStorage?

Cia getItem() Method

  1. Tau txais tus nqi ntawm cov khoom khaws cia hauv zos: var x = localStorage.
  2. Tib yam piv txwv, tab sis siv kev sib kho cia es tsis txhob cia hauv zos. Tau txais tus nqi ntawm qhov kev teev tseg cia khoom:
  3. Koj tuaj yeem tau txais tus nqi los ntawm kev siv dot notation (obj.key):
  4. Koj tuaj yeem tau txais tus nqi zoo li no:

Ib tug kuj yuav nug, sessionStorage nyob qhov twg? sessionStorage

  • sessionStorage tsuas muaj nyob rau hauv lub browser tam sim no tab. Lwm tab nrog tib nplooj ntawv yuav muaj qhov sib txawv cia. Tab sis nws tau sib koom ntawm iframes hauv tib lub tab (xav tias lawv los ntawm tib lub hauv paus chiv keeb).
  • Cov ntaub ntawv muaj sia nyob nplooj ntawv tshiab, tab sis tsis kaw / qhib lub tab.

Kuj Paub, qhov chaw cia hauv browser yog dab tsi?

Hauv zos cia - Cov chaw cia khoom siv cov localStorage kwv yees khaws cov ntaub ntawv rau koj lub vev xaib tag nrho ntawm lub hauv paus ruaj khov. Qhov ntawd txhais tau tias khaws cia hauv zos cov ntaub ntawv yuav muaj nyob rau hnub tom ntej, lub lim tiam tom ntej, lossis xyoo tom ntej tshwj tsis yog koj tshem nws.

Thaum twg kuv yuav tsum siv localStorage thiab sessionStorage?

localStorage - khaws cov ntaub ntawv tsis muaj hnub tas sij hawm. qhov rai. sessionStorage - khaws cov ntaub ntawv rau ib zaug (cov ntaub ntawv ploj thaum browser tab raug kaw)

Pom zoo: