我用php编写了一个带有tr和td标记的表中的计时器,下面的代码显示了它
$time_now=time();
$time_check=$fetch_time ['time_vam_give']+($durday1*24*60*60);
$remaining=$time_check-$time_now;
$time_remain_day=floor(($remaining)/(24*60*60));
$hours_remaining = floor(($remaining % 86400) / 3600);
$minute_remainig=floor((($remaining % 86400) % 3600)/60);
$second_reminig=((($remaining % 86400) % 3600)%60);
Echo “<table><tr class='tr1' style='background-color: #CC8A10' >
<td class='td1' style='background-color: #CC8A10'>Day</td>
<td class='td1' style='background-color: #CC8A10'>Hour</td>
<td class='td1' style='background-color: #CC8A10'>Minute</td>
<td class='td1' style='background-color: #CC8A10'>Second</td></tr>
<tr class='tr1'><td class='td1' style='background-color: #FC1359'>$time_remain_day</td>
<td class='td1' style='background-color: #FC1359'>$hours_remaining</td>
<td class='td1' style='background-color: #FC1359'>$minute_remainig</td>
<td class='td1' style='background-color: #FC1359'>$second_reminig</td></tr>”;
为了刷新我有一个刷新所有页面的代码
$page = $_SERVER['PHP_SELF'];
$sec = "5";
header("Refresh: $sec; url=$page");
但是刷新代码,刷新所有页面和所有对象都应该刷新,我只想要包含Time的变量的表中的代码,我该怎么办呢? 另外我使用Iframe但是使用这个标签,例如页面的屏幕截图,它不适合和漂亮。
echo " <iframe id='dynamic-content' src='../function/Func1.php' ></iframe>";
最诚挚的问候。
答案 0 :(得分:1)
刷新而不重新加载你应该使用ajax
你可以使用这样的东西
将2个php文件设为第一个 index.php
<script src="http://code.jquery.com/jquery-latest.js">
</script>
<script>
$(document).ready(function(){
setInterval(ajaxcall, 1000);
});
function ajaxcall(){
$.ajax({
url: 'gettime.php',
success: function(data) {
data = data.split(':');
$('#days').html(data[0]);
$('#hours').html(data[1]);
$('#minutes').html(data[2]);
$('#seconds').html(data[3]);
}
});
}
</script>
<table>
<tr class='tr1' style='background-color: #CC8A10'>
<td class='td1' style='background-color: #CC8A10'>Day</td>
<td class='td1' style='background-color: #CC8A10'>Hour</td>
<td class='td1' style='background-color: #CC8A10'>Minute</td>
<td class='td1' style='background-color: #CC8A10'>Second</td>
</tr>
<tr class='tr1'>
<td class='td1' style='background-color: #FC1359'><span id="days">0</span></td>
<td class='td1' style='background-color: #FC1359'><span id="hours">0</span></td>
<td class='td1' style='background-color: #FC1359'><span id="minutes">0</span></td>
<td class='td1' style='background-color: #FC1359'><span id="seconds">0</span></td>
</tr>
</table>
和 gettime.php
<?php
$time_now=time();
$time_check=$fetch_time ['time_vam_give']+($durday1*24*60*60);
$remaining=$time_check-$time_now;
$time_remain_day=floor(($remaining)/(24*60*60));
$hours_remaining = floor(($remaining % 86400) / 3600);
$minute_remainig=floor((($remaining % 86400) % 3600)/60);
$second_reminig=((($remaining % 86400) % 3600)%60);
echo $time_remain_day . ':' . $hours_remaining . ':' . $minute_remainig . ':' . $second_reminig;
?>
我希望能帮到你