javascript - 如何从标签中获取价值并将其价值每秒增加 1?
问题描述
我正在做一个 ajax 调用,例如返回一个 40:12:59 的字符串。该字符串带有一个已经缠绕在其周围的 td 。
我怎样才能从那里开始数秒?
我还可以返回完整的时间戳(例如 1564061259)并从那里开始工作。但最后,我需要像上面指定的日期格式。
我要显示数据的页面的 Ajax 调用:
<div id="result"></div>
<script>
function load_data()
{
$.ajax({
url:"_overview.php",
method:"POST",
success:function(data)
{
$('#result').html(data);
},
complete: function(){
$('#loading-image').hide();
}
});
}
load_data()
</script>
检查第 7 行。这是我打算在前端每秒增加一的值。这个文件(“_overview.php”)是我提出请求的文件。
<?php
include '../../variables.php';
include '../../_Database.php';
$db = Database::getInstance();
echo ' <table class="table" style="zoom: 1;">';
echo ' <thead class="thead-dark">';
echo ' <tr>';
echo ' <th scope="col">Auftrag</th>';
echo ' <th scope="col">Artikel</th>';
echo ' <th scope="col">Voraussichtliches Ende</th>';
echo ' <th scope="col">Stillstand</th>';
echo ' <th scope="col">Einrichtzeit</th>';
echo ' <th scope="col">Avg TPP</th>';
echo ' <th scope="col">Auftragsstart</th>';
echo ' <th scope="col">Laufzeit</th>';
echo ' </tr>';
echo ' </thead>';
echo ' <tbody>';
$result = mysqli_query($db->link, "SELECT * FROM `Workorder` WHERE isLocked = 0");
while ($row = mysqli_fetch_assoc($result))
{
$wo = $row['idWorkOrder'];
$article = $db->getArticle($wo);
$articleString = $db->getArticleString($db->getArticle($wo));
$db->getAllTimeStamps($wo);
$estimatedCompletion;
$estimatedCompletionFormatted;
if ($db->getEstimatedCompletion($wo) == 0)
{
$estimatedCompletionFormatted = "no data";
}
else
{
$estimatedCompletion = $db->getEstimatedCompletion($wo) + time();
$estimatedCompletionFormatted = date('Y-m-d - H:i:s', $estimatedCompletion);
}
$machinePerformance = $db->machinePerformance($wo);
$machinePerformance = ($machinePerformance - 100) * - 1;
$configPerformance = $db->getConfigPerformance($wo);
$configPerformance = ($configPerformance - 100) * - 1;
$avgTimePerPiece = $db->calculateAverageTimePerPieceTotal($wo);
$firstTimeStamp = $db->getFirstTimeStamp($wo);
$start = date('Y-m-d - H:i:s', $firstTimeStamp);
$mostRecentTimeStamp = $db->getMostRecentTimeStamp($wo);
$timeInProduction = $mostRecentTimeStamp - $firstTimeStamp;
$timeInProductionFormatted = floor($timeInProduction / 3600) .
gmdate(":i:s", $timeInProduction % 3600);
echo ' <tr>';
echo ' <td>'. $wo .'</td>';
echo ' <td>'.$articleString.'</td>';
echo ' <td>'.$estimatedCompletionFormatted.'</td>';
echo ' <td>'.$machinePerformance.'%</td>';
echo ' <td>'.$configPerformance.'%</td>';
echo ' <td>'.(int)$avgTimePerPiece.'</td>';
echo ' <td>'.$start.'</td>';
echo ' <td>'.$timeInProductionFormatted.'</td>';
echo ' </tr>';
}
echo ' </tbody>';
echo ' </table>';
?>
解决方案
您可以使用setInterval()
更新秒数,然后创建更多函数来触发分钟和小时的更改。
推荐阅读
- android - Android Studio JNI 使用 cmake 构建错误
- php - 在 curl 中点击 sms api url 时如何解决连接被拒绝的问题
- json - 在 Groovy 上执行 HTTP POST 请求
- amazon-web-services - 在现有 EC2 实例上启动 ECS 任务
- android - 如何使用 Kotlin 延迟加载协程刷新 ViewModel 数据?
- c# - 当向 RichTextBox 添加更多文本并突出显示时,它会清除所有以前的突出显示
- algorithm - 无法找出解决阵列问题的方法
- javascript - 如何使用 javascript 检测可播放的音频类型?
- java - 打印范围内的非重复随机数
- python - TypeError:得到了一个意外的关键字参数“模型”(Django)