还不太好,我不想让浏览器这样累,只是想在PHP内部实现一个时钟,然后在时钟内部插入其他代码:就像下面的JAVA程序: <SCRIPT language=JAVASCRIPT> var timerID = null; var timerRunning = false; function stopclock() { if(timerRunning) clearTimeout(timerID); timerRunning = false; } function startclock() { stopclock(); showtime(); } function showtime() { var now = new Date(); var hours = now.getHours(); var minutes = now.getMinutes(); var seconds = now.getSeconds() var timeValue = "" +hours; //定时初始化数据库的代码: timeValue += ((minutes < 10) ? ":0" : ":") + minutes timeValue += ((seconds < 10) ? ":0" : ":") + seconds
document.Calc.time.value = timeValue; // you could replace the above with this // and have a clock on the status bar: // window.status = timeValue; timerID = setTimeout("showtime()",1000); timerRunning = true; return ''; } </script>
<head>
<META HTTP-EQUIV="Refresh" Content="1;URL=test.php">
</head>
<body>
</body>
</html>---------------------
test.php:<html>
<head>
CLOCK
</head>
<body>
<?
echo date("Y年m月d日 H时i分s秒");
?>
</body>
</html>
js不是有定时执行脚本的功能吗,你课以把php代码嵌入js脚本中,试一试看看
应该可以吧
<SCRIPT language=JAVASCRIPT>
var timerID = null;
var timerRunning = false;
function stopclock()
{
if(timerRunning)
clearTimeout(timerID);
timerRunning = false;
}
function startclock()
{
stopclock();
showtime();
}
function showtime()
{
var now = new Date();
var hours = now.getHours();
var minutes = now.getMinutes();
var seconds = now.getSeconds()
var timeValue = "" +hours;
//定时初始化数据库的代码:
timeValue += ((minutes < 10) ? ":0" : ":") + minutes
timeValue += ((seconds < 10) ? ":0" : ":") + seconds
document.Calc.time.value = timeValue;
// you could replace the above with this
// and have a clock on the status bar:
// window.status = timeValue;
timerID = setTimeout("showtime()",1000);
timerRunning = true;
return '';
}
</script>
应该和在一起吧
<head>
...
</head><frameset framespacing=0 frameborder=0 border=0 rows="*,0">
<frame name=MainFrame scrolling="NO" src="./main.php">
<frame name=TimeFrame scrolling="NO" noresize src="./time.htm">
</frameset><noframes>
<body><p>您的浏览器不支持框架,无法浏览。</p></body>
</noframes>
</frameset>2. 主页面 main.php,实现你的主要功能3. 时间控制页面 time.htm,就是一段控制刷新的JS程序<script>
function Refresh()
{
parent.MainFrame.location.reload(true);
setTime("Refresh()", 1000);
}
setTime("Refresh()", 1000);
</script>怎么样,简单吧?
关键是控制刷新时间的页面和功能页面要分开,才好定时刷新(欢迎参观俺们的实验田: http://www.twotown.net)
test.php:
-----------------------------
<html>
<head>
<META HTTP-EQUIV="Refresh" Content="1;URL=test.php">
</head>
<body>
<?
echo date("Y年m月d日 H时i分s秒");
?>
</body>
</html>
隐藏框架内放的是php文件,它输出js代码,
在隐藏框架内用 parent.object.value=时间字符串 的方式来修改页面上的元素内容
sleep 暂停执行。
语法: void sleep(int seconds);
返回值: 无
本函数可暂时使程序停止执行。参数 seconds 为要暂停的秒数。usleep 暂停执行。
语法: void usleep(int micro_seconds);
返回值: 无
本函数可暂时使程序停止执行。参数 micro_seconds 为要暂停的毫秒数。可以使用类似于这样的
while(1){ //do something,
usleep(1000);
}