gpt4 book ai didi

javascript - 通过 ID 为表创建一个自动粗体 ??用javascript

转载 作者:行者123 更新时间:2023-11-28 03:10:44 27 4
gpt4 key购买 nike

首先,我为我的糟糕英语道歉,我想为一个自动通过 ID 粗体自动生成自己的表格制作一个 JavaScript,就像这里的这个但是代码不仅用于表格的几周因此,该表具有不同的时间输入,例如当时间为 08:00 时钟时,我会输入不同的时间,从 08:15 开始标记爱尔兰语始终为 +1

<td id="1">08:00</td>
<td id="1">BEKA-KAQANIK</td>
</tr>
<tr>
<td id="2">08:15</td>
<td id="2">MEDINA</td>

这是一个例子,但它只在工作日

http://jsfiddle.net/c5bHx/

var days = 'sunday,monday,tuesday,wednesday,thursday,friday,saturday'.split(',');

document.getElementById( days[(new Date()).getDay()] ).className = 'bold';
.bold {
font-weight:bold;
}
<div id="monday">Monday: 12:00-2:00</div>
<div id="tuesday">Tuesday: 11:00-3:00</div>
<div id="wednesday">wednesday: 12:00-2:00</div>
<div id="thursday">thursday: 11:00-3:00</div>
<div id="friday">friday: 12:00-2:00</div>
<div id="saturday">saturday: 11:00-3:00</div>
<div id="sunday">sunday: 12:00-2:00</div>

最佳答案

我不确定我是否正确理解了你的问题,但这里有一个例子 JSFIDDLE .它可能对您要实现的目标有所帮助。

<table>
<tr id="1530">
<td>15:30</td>
<td>A</td>
</tr>
<tr id="1545">
<td>15:45</td>
<td>B</td>
</tr>
<tr id="1600">
<td>16:00</td>
<td>C</td>
</tr>
</table>
// Initialize new Date object.
var currentDate = new Date();

// Get the hour
var currentHour = currentDate.getHours();

// Get the minutes
var currentMinute = currentDate.getMinutes();

// Bin the minutes to 15 minute increments by using modulus
// For example, xx:33 becomes 30
var minuteBin = currentMinute - (currentMinute % 15);

// Create a string that matches the HTML ids
var idString = "" + currentHour + minuteBin;

// Set the matching div class to 'bold'
document.getElementById(idString).className = 'bold';

// Log variables to console for debugging
console.log("Time =",currentHour,":",currentMinute,"bin =",minuteBin,"idString =",idString);

此示例适用于 GMT-0400 (EDT)。这将在不同的时区给出不同的结果。

如果我有任何误解,请告诉我,我会尽力更新我的答案。希望对您有所帮助!

关于javascript - 通过 ID 为表创建一个自动粗体 ??用javascript,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30697471/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com