Cancel Deleting Req-6ren">
gpt4 book ai didi

javascript - 如何使用 PHP 或 Jquery For Stored Time 创建倒计时器

转载 作者:行者123 更新时间:2023-11-28 05:11:22 25 4
gpt4 key购买 nike

<?php
$time=time();
$time_out=$time-60*24;

if($userInfo['deleteTime'] < $time_out){
?>
<td><small class="showExpire">Timeout..You Cannot Reverse the Deleted Request</small></td>
<?php } else { ?>
<td><a href="#" rel="<?php echo $userInfo['reqID']; ?>" class="cancelDelete"><small>Cancel Deleting Request</small></a></td>
<?php }?>

这是静态脚本,希望与我的代码兼容

<script language="JavaScript">
TargetDate = "12/27/2017 10:56 PM";
BackColor = "palegreen";
ForeColor = "navy";
CountActive = true;
CountStepper = -1;
LeadingZero = true;
DisplayFormat = "%%D%% Days, %%H%% Hours, %%M%% Minutes, %%S%% Seconds.";
FinishMessage = "It is finally here!";
</script>

当用户删除某些内容时我给了他 24 小时的时间来撤销删除,在 24 小时完成之前,我显示了取消删除按钮,如果从他删除后 24 小时完成,那么他将无法撤销删除,并显示超时消息。但现在我无法为该用户设置 24 小时倒计时,当他删除时,他应该知道他留下了 x 时间来撤销他的删除我如何使用倒计时这个逻辑

最佳答案

您可以使用 jquery、ajax 和 php 来实现此目的

<script>
setInterval(countDownTimer, 1000); // call your function at regular interval of time

function countDownTimer()
{
$.ajax({
url : 'your php file path',
method : 'get',
success : function(response)
{
if(response.errCode == 0)
{
$('your table id').append("<td><small class="showExpire">Timeout..You Cannot Reverse the Deleted Request</small></td>")
} else
{
$('your table id').append("<td><a href="#" rel=response.reqId class="cancelDelete"><small>Cancel Deleting Request</small></a></td>");
}
},
})
}
</script>

// in php file
<?php
$time=time();
$time_out=$time-60*24;

if($userInfo['deleteTime'] < $time_out){
return response()->json(['reqId'=>'your id']);
} else {
return response()->json(['errCode'=>0]);
}

关于javascript - 如何使用 PHP 或 Jquery For Stored Time 创建倒计时器,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41355431/

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