Storage.setItem()


驻讜谞拽爪讬讬转聽()setItem 诪讗驻砖专转 诇讛讜住讬祝 谞转讜谞讬诐 讗诇 讛讗讞住讜谉 讛诪拽讜诪讬 讘讗诪爪注讜转 砖谞讬 驻专诪讟专讬诐: 砖诐 诪驻转讞聽讜注专讱 砖讗讜转诐 转讬爪讜专 讗讜 转注讚讻谉 讘诪讬讚讛 讜拽讬讬诪讬诐.

转讞讘讬专

storage.setItem(keyName, keyValue);

驻专诪讟专讬诐

keyName
诪讻讬诇 讗转 砖诪讜 砖诇 讛诪驻转讞 讗讜转讜 讬砖 诇讬爪讜专 讗讜 诇注讚讻谉.
keyValue
诪讻讬诇 讗转 砖诐 讛注专讱 砖讬转讜讜住祝 诇诪驻转讞 讗讜转讜 讗谞讜 讬讜爪专讬诐 讗讜 诪注讚讻谞讬诐.

注专讱 讞讜讝专

undefined.

讛讞专讙讜转

讘诪讬讚讛 讜讛讗讞住讜谉 诪诇讗 讛诪注专讻讜转 注砖讜讬讛 诇谞拽讜转 谞转讜谞讬诐 诪讛讗讞住讜谉 讛诪拽讜诪讬.
讘讙专住讛 讛谞讬讬讚转 砖诇 讚驻讚驻谉聽Safari, 讘诪讬讚讛 讜讛诪砖转诪砖 谞讻谞住 讗诇 诪爪讘 驻专讟讬 讛诪注专讻转 讗讬谞讛 砖讜诪专转 谞转讜谞讬诐 讘讗讞住讜谉 讛诪拽讜诪讬 讜诪住讬专讛 讗讜转诐 讘讗讜驻谉 讗讜讟讜诪讟讬 讘砖诇 诪讙讘诇转 讙讜讚诇 砖诇 0 讘转讬诐.

讚讜讙诪讗讜转

讛驻讜谞拽爪讬讛 讛讘讗讛 讬讜爪专转 砖诇讜砖讛 驻专讬讟讬 谞转讜谞讬诐 讘转讜讱 讛讗讞住讜谉 讛诪拽讜诪讬.

function populateStorage() {
  localStorage.setItem('bgcolor', 'red');
  localStorage.setItem('font', 'Helvetica');
  localStorage.setItem('image', 'myCat.png');
}

诪驻专讟

Specification Status Comment
HTML Living Standard
The definition of 'Storage.setItem' in that specification.
Living Standard

转讗讬诪讜转 讚驻讚驻谉

Update compatibility data on GitHub
DesktopMobile
ChromeEdgeFirefoxInternet ExplorerOperaSafariAndroid webviewChrome for AndroidFirefox for AndroidOpera for AndroidSafari on iOSSamsung Internet
setItemChrome Full support 4Edge Full support 12Firefox Full support 3.5IE Full support 8Opera Full support 10.5Safari Full support 4WebView Android Full support 鈮37Chrome Android Full support 18Firefox Android Full support 6Opera Android Full support 11Safari iOS Full support 3.2Samsung Internet Android Full support 1.0

Legend

Full support
Full support

专讗讜 讙诐