jquery - codeigniter 和 ajax 中的计时器
问题描述
我需要在 codeigniter 、 mysql 和 ajax 中使用计时器,因为天数来自每个产品的数据库。
<td id="timer"><?=$data['auction_end_time']?></td>
数据在几天内来自数据库,我想显示计时器。这是我的网站的链接,你可以在这里看到。
请指导我...!
解决方案
假设我们有以下 php 函数(这可以改进)
function auction_end_time($future_date) {
$now = new DateTime();
$future_date = new DateTime($future_date);
if($future_date <= $now)
return 'This offer has expired!';
$interval = $future_date->diff($now);
return $interval->format("%a days %h:%i:%s");
}
在你的 html 代码中
<td id="timer"><?=auction_end_time($data['auction_end_time'])?></td>
该解决方案是静态的。对于动态倒计时,您可以使用 jquery 插件,我找到了这个jQuery.countdown 插件
推荐阅读
- python - 如何使 satusbar 仅适用于特定状态(Odoo13)
- android - Flutter Row() - 均匀对齐 3 个小部件
- java - java swing手动启动一个没有用户输入的事件
- python - 在谷歌 colab 中使用 argparse。不使用文件夹名称“gdrive/My Drive/”中的空间
- python - 如何使用 LeaveOneOut 解决 TypeError
- json - Swift - 如何使用可编码的嵌套数组的 JSON 进行 JSONDecode(其中没有键或名称的数组,根据给出的示例)
- laravel - 如何将 react-native-audio-record 录制的音频文件发送到服务器?
- python - 如何隔离打印输出中的第四行?
- javascript - 转换 Scratch 颜色
- php - 在服务类中使用 Symfonybundle 中的参数