0

这是我的脚本,它是 php 和 javascript 的组合

<?php
$countdown = strtotime("22:00") - time();
$itemtime = "22:00";
$realtime = substr(date('H:i'),0,5);
?>

<script>
var itemtime = "$itemtime";
var countdown = '$countdown';
var url = "$redirectpage";
var realtime = "$realtime";

// HOW WILL I ADD AN IF STATEMENT WITH THE SETTIMEOUT FUNCTION
// WHEREBY, if(realtime == itemtime) ..that's the only time the 
// redirection should occur

setTimeout(function(){
 location.href='$redirectpage'; 
    },countdown * 1000);

</script>
4

2 回答 2

2
<?php
$countdown = strtotime("22:00") - time();
$itemtime = "22:00";
$realtime = substr(date('H:i'),0,5);
?>

<script>
var itemtime = "<?php echo $itemtime;?>";
var countdown = '<?php echo $countdown;?>';
var url = "$redirectpage";
var realtime = "<?php echo $realtime;?>";

// HOW WILL I ADD AN IF STATEMENT WITH THE SETTIMEOUT FUNCTION
// WHEREBY, if(realtime == itemtime) ..that's the only time the 
// redirection should occur

setTimeout(function(){
 if(realtime == itemtime) location.href='$redirectpage'; 
},countdown * 1000);
</script>

假设$redirectpage是在 JavaScript 而不是 PHP 中设置的。如果它是在 PHP 中设置的,你需要像我上面那样分配它。

于 2013-01-10T14:24:30.880 回答
0

我最终得到了自己的解决方案,我把它放在 setTimeout 函数中

if(countdown < 0) setTimeout("location.reload(true);",1000); location.href= "$redirectpage";
于 2013-01-11T03:02:42.960 回答