簡體   English   中英

使用javascript僅從localstorage中刪除特定項目?

[英]Delete only specific item from localstorage using javascript?

即使在客戶端從我的網站注銷后,我也需要存儲Storageselectedclient以便當我們再次登錄時,最后選擇的客戶端將顯示出來,但它不起作用,我的整個項目也在Angular 7 中

在此處輸入圖片說明

這是我的工作代碼,其中也有空閑注銷功能

  var IDLE_TIMEOUT = 10; //seconds
      var _idleSecondsCounter = 0;

      document.onclick = function () {
          _idleSecondsCounter = 0;
      };

      document.onmousemove = function () {
          _idleSecondsCounter = 0;
      };

      document.onkeypress = function () {
          _idleSecondsCounter = 0;
      };
      $(window).on('hashchange', function(e){
        _idleSecondsCounter = 0;
       });
       window.setInterval(CheckIdleTime, 1000);


      function CheckIdleTime() {
          _idleSecondsCounter++;
          var oPanel = document.getElementById("SecondsUntilExpire");
          if (oPanel)
              oPanel.innerHTML = (IDLE_TIMEOUT - _idleSecondsCounter) + "";
          if (_idleSecondsCounter >= IDLE_TIMEOUT) {
              localStorage.clear();
              window.location.replace(location.origin);

          }
      } 

您可以使用removeItem()刪除數據

localStorage.removeItem('key')

使用clear()將清除所有本地存儲。

localStorage.clear()

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM