我刚刚得到了一个集成 PHP 日期函数和 jQuery 的教程。
我想自定义脚本,以便在特定时间到达其重定向到另一个页面。
我尝试自己做,但它无法正常工作。我已在此处添加了教程链接。
从服务器获取日期的 PHP 代码
<?php
date_default_timezone_set('GMT');
$currentTime = date('H:i:s');
$currentDay = date('w');
$delTimeStart = '00:00:00';
$delTimeEnd = '14:30:00';
if ($currentTime >= $delTimeStart && $currentTime < $delTimeEnd && $currentDay > 0 && $currentDay < 6){
$css = 'display: block;';
} else {
$css = 'display: none;';
}
?>
JS脚本
<script type="text/javascript">
$('#countdowntimer').countdown('<?php $date = strtotime("+1 day"); echo date('Y/m/d', $date); ?> 14:30:00').on('update.countdown', function(event) {
var $this = $(this).html(event.strftime(''
+ '%H Hours '
+ '%M Minutes '
+ '%S Seconds'
));
});
</script>
最佳答案
试试这个 - 收集自 the source :
$('#countdowntimer').countdown('<?php $date = strtotime("+1 day"); echo date('Y/m/d', $date); ?> 14:30:00')
.on('update.countdown', function(event) {
$(this).html(event.strftime(''
+ '%H Hours '
+ '%M Minutes '
+ '%S Seconds'
));
})
.on('finish.countdown', function(event) {
location.replace("someurl");
});
关于javascript - PHP 和 jquery 倒计时,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33235872/