简体   繁体   English

当页面使用Javascript刷新时,如何保持对类所做的更改

[英]How to keep changes made to a class when the page refreshes with Javascript

I have a table of data for the user to look through and make changes. 我有一张数据表供用户浏览和更改。 They have the option to delete a row if they want. 他们可以选择删除行。 When they delete a row it sends back to the db what row is to be deleted. 当他们删除一行时,它会将要删除的行发送回数据库。 For the user the row won't delete right away but it will get a new class 'deleted' that has some styles to let the user know it's being deleted. 对于用户而言,该行不会立即删除,但是它将获得一个新的“已删除”类,该类具有一些样式,可以让用户知道它正在被删除。 I also have the page refreshing every 10 minutes and when it refreshes the new added 'deleted' class goes away. 我还每10分钟刷新一次页面,刷新时,新添加的“已删除”类消失。

How can I get it that the class will stay on the row when the page refreshes? 如何刷新页面刷新时类仍停留在行上?

Here is the timer function for the timer to know when to refresh the page. 这是计时器功能,计时器可以知道何时刷新页面。 I'm using ajax to refresh the page. 我正在使用ajax刷新页面。

        function startClock() {
          // Get the time to stop the effect
          var stopTime = new Date();
          stopTime.setMinutes(stopTime.getMinutes() + 10);
          // Get a reference to the timer so it can be cancelled later
          timer = setInterval(function () {
              // Check to see if the timer should stop
              var currentTime = new Date();
              if (currentTime < stopTime) {
                  triggerDataTable(); //refresh dataTable
                  var randomnumber = Math.floor(Math.random() * 100);
              } else {
                  // Stop the timer
                  clearInterval(timer);
              }
          }, 600000);
      }

Would I use localStorage? 我会使用localStorage吗? If so how would I actually do it? 如果是这样,我实际上将如何做? I'm not familiar with storing local values or anything like that. 我不熟悉存储本地值或类似的东西。

I'm not 100% sure about this but what about doing something like this: 我不是对此有100%的把握,但是做这样的事情怎么办:

var deletedRow = $(".deleted");
localStorage.setItem( deletedRow, $(".deleted").val() );

try using sessionstorage over localstorage 尝试在本地存储上使用sessionstorage

Session Storage property maintains a separate storage area for each given origin and for a session . 会话存储属性为每个给定的来源和会话维护一个单独的存储区域。

Local Storage does the same thing, but persists even when the browser is closed and reopened. 本地存储执行相同的操作,但是即使关闭并重新打开浏览器也可以保留。

sessionStorage.setItem('item', value);
sessionStorage.getItem('item');

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM