【问题标题】:Get and Set javascript value in localStorage在 localStorage 中获取和设置 javascript 值
【发布时间】:2019-12-04 13:40:41
【问题描述】:

我想使用 LocalStorage 获取 javascript 值并将值存储在 php 中。我不知道如何设置值,所以请提供解决方案。

var getdate1 = document.getElementById("eventDayName").innerHTML = selectedDate.toLocaleString("en-US", {
            month: "long",
            day: "numeric",
            year: "numeric"
        }); 


        localStorage.getItem('getdate1', val);

【问题讨论】:

标签: javascript php local-storage


【解决方案1】:

要在 localStorage 中设置值,请使用 window.localStorage.setItem 之类的

window.localStorage.setItem('getdate1', JSON.stringify(getdate1));

var getdate1 =document.getElementById("eventDayName").innerHTML = selectedDate.toLocaleString("en-US", {
            month: "long",
            day: "numeric",
            year: "numeric"
        }); 
window.localStorage.setItem('getdate1', JSON.stringify(getdate1));

【讨论】:

  • 设置值 localStorage.setItem("getdate1", getdate1); //get var getval = localStorage.getItem("getdate1");
  • 如何将此值设置为 php 内部值
  • @sixthstar
  • @sixthstar 设置 javascript 或 PHP 值
  • 伟大的先生。这工作正常..非常感谢。
【解决方案2】:

使用此代码:

// Store
localStorage.setItem("lastname", "Smith");

//get
localStorage.getItem("lastname");

【讨论】:

  • 我想设置一个变量并分配给 php 值,这是主要逻辑。 (例如)
  • 这里的php值是什么意思
  • 你可以通过输入的id来绑定输入
  • var x = localStorage.getItem("lastname");
  • $('#inputid').val(x);
猜你喜欢
  • 2021-10-25
  • 1970-01-01
  • 2016-12-24
  • 2017-04-09
  • 2014-03-15
  • 2018-11-26
  • 1970-01-01
  • 2015-01-31
  • 1970-01-01
相关资源
最近更新 更多