将时间戳发布到本地商店的 OnChange 事件 - 适用于 7 个用户的团队

onchange event with timestamp posted to local storeage - for team of 7 users

本文关键字:事件 OnChange 适用于 团队 用户 时间戳      更新时间:2023-09-26

好的,我有一个7人的团队,我需要使这段代码独立地为所有用户工作。我遇到的问题是,当我发布到本地存储以进行一个用户更改然后调用数据时,它会调用所有用户的数据,而不仅仅是进行更改的数据。仅查看一个用户"David"的示例,但请记住,我团队中还有其他 6 个人。在此处查看 JSFIDDLE 代码 -> http://jsfiddle.net/skippd01/optwxh0d/

 <script>
 function foo(a) {
 //alert(a.value);
 var d = new Date();
 var c = document.getElementById("time").innerHTML;
 c = c + a.value + " was selected at: " + d.toString();
 document.getElementById("time").innerHTML = c + '<br/>';
 localStorage.setItem(a.value, d.toString());
 }
 function load() {
 var c = "Wholesale Pictures: " + localStorage.getItem("Wholesale Pictures") + '<br/>';
 c += "NS Pictures:" + localStorage.getItem("NS Pictures") + '<br/>';
 c += "NS ERO's:" + localStorage.getItem("NS ERO's") + '<br/>';
 c += "BL ERO's:" + localStorage.getItem("BL ERO's") + '<br/>';
 c += "Wholesale Staging:" + localStorage.getItem("Wholesale Staging") + '<br/>';
 c += "Wholesale Scan:" + localStorage.getItem("Wholesale Scan") + '<br/>';
 c += "Sirius Tags:" + localStorage.getItem("Sirius Tags") + '<br/>';
 c += "Lunch Break:" + localStorage.getItem("Lunch Break") + '<br/>';
 document.getElementById("log").innerHTML = c;
 }
 </script>
<h2>David</h2>
<p id="log"></p>
此"日志"

是单击"活动日志"按钮后显示下面选择的选项的历史记录的位置(请参阅下面的按钮)。它还显示他们选择的选项的时间戳。

<select id="options" class="form-control" onchange="foo(this)">
<option>Select Work Area</option>
<option>NS Pictures</option>
<option>NS ERO's</option>
<option>BL ERO's</option>
<option>Wholesale Staging</option>
<option>Wholesale Scan</option>
<option>Wholesale Pictures</option>
<option>Sirius Tags</option>
<option>Lunch Break</option>
</select>
<div class="buttons">
<button id="History" onclick="load()">Activity Log</button>
//I select "Activity Log" to get a daily activity log for "David" in this example.This is the log that is stored in the web browser local storage. 
</div>
<p id="time"><br/></p> 

这个"时间"id只是用户从上面选择的选项的实时显示,并在刷新屏幕后消失。

我不完全清楚你想实现什么,但我会

试一试。

听起来您想存储每个用户的输入(我在这里看不到),并保持谨慎。

似乎您可以通过根据用户在保存和检索时命名您的本地存储来轻松实现这一点。下面将为 setItem 和 getItem 创建一个包装器。

var currentUser = "david";
function setItem(key, value) {
  // namespace by the currentUser, and assuming you'll always pass a string for value
  return localStorage.setItem(currentUser + ":" + key, value);
}
function getItem(key) {
  return localStorage.getItem(currentUser + ":" + key);
}