我有一个调度应用程序,它在顶部显示资产表,在侧面显示时间单元。从上午 12:00 到晚上 11:45,时间单元格以 15 分钟递增。当页面加载或刷新时,我希望屏幕专注于当前时间单元格。我想我的代码很接近,但我不确定它为什么不起作用。这是我正在使用的 jquery:
$(document).ready(function()
{
var now = new Date();
now = formatTimes(now);
alert ("Looking for " + now);
$('.timeColumnOdd[innerHTML="4:15 pm"]').focus();
var thisScript = '';
var roleID = document.getElementById('roleID').value;
if (roleID == 5)
{
thisScript = '../js/tentativeSchedule.js';
}
else
{
thisScript = 'schedule.js';
}
var script = document.createElement("script");
script.type = "text/javascript";
script.src = thisScript;
document.getElementsByTagName('body')[0].appendChild(script);
});
function formatTimes(tm)
{
var hour = tm.getHours();
var minutes = tm.getMinutes();
if(minutes < 15 && minutes > 00){minutes = 15;}
if(minutes < 30 && minutes > 15){minutes = 30;}
if(minutes > 30 && minutes < 45){minutes = 45;}
if(minutes > 45 && minutes <= 59){minutes = 0, hour = tm.getHours()+1}
if(minutes<1){minutes='0'+minutes}
var timePiece = null;
if (hour >= 12)
{
hour = hour - 12;
if (hour == 00)
{
hour = hour + 1;
}
if (hour < 10)
{
var timePiece = hour + ":" + minutes + ' pm';
}
else
var timePiece = hour + ":" + minutes + ' pm';
}
else
{
var timePiece = hour + ":" + minutes + ' am';
}
return timePiece;
}
这是创建时间列的 php 部分:
$table->setCellAttributes(0, 0, 'class="timeColumn"');
$table->setHeaderContents(0,0, 'Time');
$now = new DateTime($pickedDate);
$now = date_format($now,'U');
$offset = ($now % 900);
$now = $now-$offset;
for ($i = 1;$i < 97; $i++)
{
$table->setCellAttributes($i,0,'class="timeColumnEven"');
$table->setHeaderContents($i++,0, date('g:i a',$now));
$now += 900;
for ($x = 0; $x<2;$x++)
{
$table->setCellAttributes($i,0,'class="timeColumnOdd"');
$table->setHeaderContents($i++,0, date('g:i a',$now));
$now += 900;
}
$table->setCellAttributes($i,0,'class="timeColumnOdd"');
$table->setHeaderContents($i,0, date('g:i a',$now));
$now += 900;
}
我知道时间目前是硬编码的,那是因为我试图让它在没有可变输入的情况下工作。