作者热门文章
- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我正在努力使唯一的粉红色单元格与当前日期和时间相匹配。但是,现在我有了它,所以整行时间都突出显示为粉红色。我还按半小时对它进行了排序,因此如果是下午 3:11,则下午 3:00 的行将突出显示。我想要它的示例:如果时间是 2:30 并且是星期一,我希望与星期一和 2:30 匹配的单元格为粉红色。
let today = new Date();
var d = today.getDay();
var weeks = document.getElementsByTagName("tr");
for (var i = 0; i < weeks.length; i++) {
var currentWeek = weeks[i].children;
if (d < currentWeek.length) {
currentWeek[d + 1].style.backgroundColor = "lightblue";
}
}
var n = today.getHours();
var x = today.getMinutes();
if (x <= 29) {
x = "00";
}
if (x >= 30) {
x = "30";
}
if (n >= 12) {
z = "PM";
} else {
z = "AM";
}
var todayyy = n + ":" + x + z;
var datte = document.getElementById(todayyy).parentNode.children;
for (var i = 0; i < datte.length; i++) {
datte[i].style.backgroundColor = "pink";
}
<!DOCTYPE html>
<html lang="en-US">
<head>
<title>Calendar</title>
<meta charset="utf-8">
<style>
</style>
</head>
<body>
<table class="tg">
<tr>
<th class="time">time</th>
<th class="day" id="sunday">sun</th>
<th class="day" id="monday">mon</th>
<th class="day" id="tuesday">tue</th>
<th class="day" id="wensday">wed</th>
<th class="day" id="thursday">thu</th>
<th class="day" id="friday">fri</th>
<th class="day" id="saturday">sat</th>
</tr>
<tr>
<td class="date" id="8:00AM">8:00 AM</td>
<td class="day"></td>
<td class="day"></td>
<td class="day"></td>
<td class="day"></td>
<td class="day"></td>
<td class="day"></td>
<td class="day"></td>
</tr>
<tr>
<td class="date" id="8:30AM">8:30 AM</td>
<td class="day"></td>
<td class="day"></td>
<td class="day"></td>
<td class="day"></td>
<td class="day"></td>
<td class="day"></td>
<td class="day"></td>
</tr>
<tr>
<td class="date" id="9:00AM">9:00 AM</td>
<td class="day"></td>
<td class="day"></td>
<td class="day"></td>
<td class="day"></td>
<td class="day"></td>
<td class="day"></td>
<td class="day"></td>
</tr>
<tr>
<td class="date" id="9:30AM">9:30 AM</td>
<td class="day"></td>
<td class="day"></td>
<td class="day"></td>
<td class="day"></td>
<td class="day"></td>
<td class="day"></td>
<td class="day"></td>
</tr>
<tr>
<td class="date" id="10:00AM">10:00 AM</td>
<td class="day"></td>
<td class="day"></td>
<td class="day"></td>
<td class="day"></td>
<td class="day"></td>
<td class="day"></td>
<td class="day"></td>
</tr>
<tr>
<td class="date" id="10:30AM">10:30 AM</td>
<td class="day"></td>
<td class="day"></td>
<td class="day"></td>
<td class="day"></td>
<td class="day"></td>
<td class="day"></td>
<td class="day"></td>
</tr>
<tr>
<td class="date" id="11:00AM">11:00 AM</td>
<td class="day"></td>
<td class="day"></td>
<td class="day"></td>
<td class="day"></td>
<td class="day"></td>
<td class="day"></td>
<td class="day"></td>
</tr>
<tr>
<td class="date" id="11:30AM">11:30 AM</td>
<td class="day"></td>
<td class="day"></td>
<td class="day"></td>
<td class="day"></td>
<td class="day"></td>
<td class="day"></td>
<td class="day"></td>
</tr>
<tr>
<td class="date" id="12:00PM">12:00 PM</td>
<td class="day"></td>
<td class="day"></td>
<td class="day"></td>
<td class="day"></td>
<td class="day"></td>
<td class="day"></td>
<td class="day"></td>
</tr>
<tr>
<td class="date" id="12:30PM">12:30 PM</td>
<td class="day"></td>
<td class="day"></td>
<td class="day"></td>
<td class="day"></td>
<td class="day"></td>
<td class="day"></td>
<td class="day"></td>
</tr>
<tr>
<td class="date" id="13:00PM">1:00 PM</td>
<td class="day"></td>
<td class="day"></td>
<td class="day"></td>
<td class="day"></td>
<td class="day"></td>
<td class="day"></td>
<td class="day"></td>
</tr>
<tr>
<td class="date" id="13:30PM">1:30 PM</td>
<td class="day"></td>
<td class="day"></td>
<td class="day"></td>
<td class="day"></td>
<td class="day"></td>
<td class="day"></td>
<td class="day"></td>
</tr>
<tr>
<td class="date" id="14:00PM">2:00 PM</td>
<td class="day"></td>
<td class="day"></td>
<td class="day"></td>
<td class="day"></td>
<td class="day"></td>
<td class="day"></td>
<td class="day"></td>
</tr>
<tr>
<td class="date" id="14:30PM">2:30 PM</td>
<td class="day"></td>
<td class="day"></td>
<td class="day"></td>
<td class="day"></td>
<td class="day"></td>
<td class="day"></td>
<td class="day"></td>
</tr>
<tr>
<td class="date" id="15:00PM">3:00 PM</td>
<td class="day"></td>
<td class="day"></td>
<td class="day"></td>
<td class="day"></td>
<td class="day"></td>
<td class="day"></td>
<td class="day"></td>
</tr>
<tr>
<td class="date" id="15:30PM">3:30 PM</td>
<td class="day"></td>
<td class="day"></td>
<td class="day"></td>
<td class="day"></td>
<td class="day"></td>
<td class="day"></td>
<td class="day"></td>
</tr>
<tr>
<td class="date" id="16:00PM">4:00 PM</td>
<td class="day"></td>
<td class="day"></td>
<td class="day"></td>
<td class="day"></td>
<td class="day"></td>
<td class="day"></td>
<td class="day"></td>
</tr>
<tr>
<td class="date" id="16:30PM">4:30 PM</td>
<td class="day"></td>
<td class="day"></td>
<td class="day"></td>
<td class="day"></td>
<td class="day"></td>
<td class="day"></td>
<td class="day"></td>
</tr>
<tr>
<td class="date" id="17:00PM">5:00 PM</td>
<td class="day"></td>
<td class="day"></td>
<td class="day"></td>
<td class="day"></td>
<td class="day"></td>
<td class="day"></td>
<td class="day"></td>
</tr>
<tr>
<td class="date" id="17:30PM">5:30 PM</td>
<td class="day"></td>
<td class="day"></td>
<td class="day"></td>
<td class="day"></td>
<td class="day"></td>
<td class="day"></td>
<td class="day"></td>
</tr>
<tr>
<td class="date" id="18:00PM">6:00 PM</td>
<td class="day"></td>
<td class="day"></td>
<td class="day"></td>
<td class="day"></td>
<td class="day"></td>
<td class="day"></td>
<td class="day"></td>
</tr>
<tr>
<td class="date" id="18:30PM">6:30 PM</td>
<td class="day"></td>
<td class="day"></td>
<td class="day"></td>
<td class="day"></td>
<td class="day"></td>
<td class="day"></td>
<td class="day"></td>
</tr>
<tr>
<td class="date" id="19:00PM">7:00 PM</td>
<td class="day"></td>
<td class="day"></td>
<td class="day"></td>
<td class="day"></td>
<td class="day"></td>
<td class="day"></td>
<td class="day"></td>
</tr>
<tr>
<td class="date" id="19:30PM">7:30 PM</td>
<td class="day"></td>
<td class="day"></td>
<td class="day"></td>
<td class="day"></td>
<td class="day"></td>
<td class="day"></td>
<td class="day"></td>
</tr>
<tr>
<td class="date" id="20:00PM">8:00 PM</td>
<td class="day"></td>
<td class="day"></td>
<td class="day"></td>
<td class="day"></td>
<td class="day"></td>
<td class="day"></td>
<td class="day"></td>
</tr>
</table>
<script>
</script>
</body>
</html>
最佳答案
在一周中的几天循环中,设置一个 col
变量,然后将它传递给您的 datte
数组:
datte[col].style.backgroundColor = "pink";
let today = new Date();
var d = today.getDay();
var weeks = document.getElementsByTagName("tr");
let col;
for (var i = 0; i < weeks.length; i++) {
var currentWeek = weeks[i].children;
if (d < currentWeek.length) {
currentWeek[d + 1].style.backgroundColor = "lightblue"
col = d + 1
}
}
var n = today.getHours();
var x = today.getMinutes();
if (x <= 29) {
x = "00";
}
if (x >= 30) {
x = "30";
}
if (n >= 12) {
z = "PM";
} else {
z = "AM";
}
var todayyy = n + ":" + x + z;
var datte = document.getElementById(todayyy).parentNode.children;
datte[col].style.backgroundColor = "pink";
<!DOCTYPE html>
<html lang="en-US">
<head>
<title>Calendar</title>
<meta charset="utf-8">
<style>
</style>
</head>
<body>
<table class="tg">
<tr>
<th class="time">time</th>
<th class="day" id="sunday">sun</th>
<th class="day" id="monday">mon</th>
<th class="day" id="tuesday">tue</th>
<th class="day" id="wensday">wed</th>
<th class="day" id="thursday">thu</th>
<th class="day" id="friday">fri</th>
<th class="day" id="saturday">sat</th>
</tr>
<tr>
<td class="date" id="8:00AM">8:00 AM</td>
<td class="day"></td>
<td class="day"></td>
<td class="day"></td>
<td class="day"></td>
<td class="day"></td>
<td class="day"></td>
<td class="day"></td>
</tr>
<tr>
<td class="date" id="8:30AM">8:30 AM</td>
<td class="day"></td>
<td class="day"></td>
<td class="day"></td>
<td class="day"></td>
<td class="day"></td>
<td class="day"></td>
<td class="day"></td>
</tr>
<tr>
<td class="date" id="9:00AM">9:00 AM</td>
<td class="day"></td>
<td class="day"></td>
<td class="day"></td>
<td class="day"></td>
<td class="day"></td>
<td class="day"></td>
<td class="day"></td>
</tr>
<tr>
<td class="date" id="9:30AM">9:30 AM</td>
<td class="day"></td>
<td class="day"></td>
<td class="day"></td>
<td class="day"></td>
<td class="day"></td>
<td class="day"></td>
<td class="day"></td>
</tr>
<tr>
<td class="date" id="10:00AM">10:00 AM</td>
<td class="day"></td>
<td class="day"></td>
<td class="day"></td>
<td class="day"></td>
<td class="day"></td>
<td class="day"></td>
<td class="day"></td>
</tr>
<tr>
<td class="date" id="10:30AM">10:30 AM</td>
<td class="day"></td>
<td class="day"></td>
<td class="day"></td>
<td class="day"></td>
<td class="day"></td>
<td class="day"></td>
<td class="day"></td>
</tr>
<tr>
<td class="date" id="11:00AM">11:00 AM</td>
<td class="day"></td>
<td class="day"></td>
<td class="day"></td>
<td class="day"></td>
<td class="day"></td>
<td class="day"></td>
<td class="day"></td>
</tr>
<tr>
<td class="date" id="11:30AM">11:30 AM</td>
<td class="day"></td>
<td class="day"></td>
<td class="day"></td>
<td class="day"></td>
<td class="day"></td>
<td class="day"></td>
<td class="day"></td>
</tr>
<tr>
<td class="date" id="12:00PM">12:00 PM</td>
<td class="day"></td>
<td class="day"></td>
<td class="day"></td>
<td class="day"></td>
<td class="day"></td>
<td class="day"></td>
<td class="day"></td>
</tr>
<tr>
<td class="date" id="12:30PM">12:30 PM</td>
<td class="day"></td>
<td class="day"></td>
<td class="day"></td>
<td class="day"></td>
<td class="day"></td>
<td class="day"></td>
<td class="day"></td>
</tr>
<tr>
<td class="date" id="13:00PM">1:00 PM</td>
<td class="day"></td>
<td class="day"></td>
<td class="day"></td>
<td class="day"></td>
<td class="day"></td>
<td class="day"></td>
<td class="day"></td>
</tr>
<tr>
<td class="date" id="13:30PM">1:30 PM</td>
<td class="day"></td>
<td class="day"></td>
<td class="day"></td>
<td class="day"></td>
<td class="day"></td>
<td class="day"></td>
<td class="day"></td>
</tr>
<tr>
<td class="date" id="14:00PM">2:00 PM</td>
<td class="day"></td>
<td class="day"></td>
<td class="day"></td>
<td class="day"></td>
<td class="day"></td>
<td class="day"></td>
<td class="day"></td>
</tr>
<tr>
<td class="date" id="14:30PM">2:30 PM</td>
<td class="day"></td>
<td class="day"></td>
<td class="day"></td>
<td class="day"></td>
<td class="day"></td>
<td class="day"></td>
<td class="day"></td>
</tr>
<tr>
<td class="date" id="15:00PM">3:00 PM</td>
<td class="day"></td>
<td class="day"></td>
<td class="day"></td>
<td class="day"></td>
<td class="day"></td>
<td class="day"></td>
<td class="day"></td>
</tr>
<tr>
<td class="date" id="15:30PM">3:30 PM</td>
<td class="day"></td>
<td class="day"></td>
<td class="day"></td>
<td class="day"></td>
<td class="day"></td>
<td class="day"></td>
<td class="day"></td>
</tr>
<tr>
<td class="date" id="16:00PM">4:00 PM</td>
<td class="day"></td>
<td class="day"></td>
<td class="day"></td>
<td class="day"></td>
<td class="day"></td>
<td class="day"></td>
<td class="day"></td>
</tr>
<tr>
<td class="date" id="16:30PM">4:30 PM</td>
<td class="day"></td>
<td class="day"></td>
<td class="day"></td>
<td class="day"></td>
<td class="day"></td>
<td class="day"></td>
<td class="day"></td>
</tr>
<tr>
<td class="date" id="17:00PM">5:00 PM</td>
<td class="day"></td>
<td class="day"></td>
<td class="day"></td>
<td class="day"></td>
<td class="day"></td>
<td class="day"></td>
<td class="day"></td>
</tr>
<tr>
<td class="date" id="17:30PM">5:30 PM</td>
<td class="day"></td>
<td class="day"></td>
<td class="day"></td>
<td class="day"></td>
<td class="day"></td>
<td class="day"></td>
<td class="day"></td>
</tr>
<tr>
<td class="date" id="18:00PM">6:00 PM</td>
<td class="day"></td>
<td class="day"></td>
<td class="day"></td>
<td class="day"></td>
<td class="day"></td>
<td class="day"></td>
<td class="day"></td>
</tr>
<tr>
<td class="date" id="18:30PM">6:30 PM</td>
<td class="day"></td>
<td class="day"></td>
<td class="day"></td>
<td class="day"></td>
<td class="day"></td>
<td class="day"></td>
<td class="day"></td>
</tr>
<tr>
<td class="date" id="19:00PM">7:00 PM</td>
<td class="day"></td>
<td class="day"></td>
<td class="day"></td>
<td class="day"></td>
<td class="day"></td>
<td class="day"></td>
<td class="day"></td>
</tr>
<tr>
<td class="date" id="19:30PM">7:30 PM</td>
<td class="day"></td>
<td class="day"></td>
<td class="day"></td>
<td class="day"></td>
<td class="day"></td>
<td class="day"></td>
<td class="day"></td>
</tr>
<tr>
<td class="date" id="20:00PM">8:00 PM</td>
<td class="day"></td>
<td class="day"></td>
<td class="day"></td>
<td class="day"></td>
<td class="day"></td>
<td class="day"></td>
<td class="day"></td>
</tr>
</table>
<script>
</script>
</body>
</html>
关于javascript - 制作与当前日期和时间相匹配的单元格,某种颜色,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59381429/
现在我正在尝试实现 flash programming specification对于 PIC32MX。我正在使用 PIC32MX512L 和 PIC32MX512H。 PIC32MX512L最终必须
我是一名优秀的程序员,十分优秀!