简体   繁体   English

Javascript Function 用于在一天中的特定时间突出显示某些内容

[英]Javascript Function for Highlighting something at certain time of day

I have a spreadsheet that displays every member of my staff's name and what time their lunch break is.我有一个电子表格,其中显示了我员工的每个成员的姓名以及他们的午休时间。 We use this list to assign them new cases that come in, but obviously we can't assign them a case when they are at lunch.我们使用此列表为他们分配新的病例,但显然我们不能在他们吃午饭时为他们分配病例。

I would like to figure out a way to highlight or "gray out" their names when they're on lunch, and then change back when their lunch time is over.我想想办法在他们吃午饭时突出显示或“变灰”他们的名字,然后在他们的午餐时间结束时改回来。

I think you can use a conditional class with css and JavaScript maybe inside window.onLoad.. Something like that:我认为您可以使用有条件的 class 和 css 和 JavaScript 可能在 Z05B8C74CBD96FBF2DE4C1A3.FLoad 之类的东西里面。

CSS: CSS:

.class{
...
}

.classHighLight{
...
}

JS: JS:

window.onload = function() {
   var currentHour = new Date().getHours();
   var arrStaffs = Here you load your spreadsheet's hours

   arrStaffs.forEach((member) => {
       if(member.lunchHour == currentHour){
           document.getElementById(*Member's button ID*).className = 'classHighLight';
       }
   })
};

That way, when you visit the page, your onLoad function will highligth members that have the same lunchHour as the current hour.这样,当您访问该页面时,您的 onLoad function 将突出显示与当前时间具有相同午餐时间的成员。 I dont't know your spreadsheet data layout, but I'm pretending you have something like:我不知道你的电子表格数据布局,但我假装你有类似的东西:

Mike - 14 / Peter - 12迈克 - 14 / 彼得 - 12

Hope it helps you:)希望对你有帮助:)

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

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