Board logo

标题: javacript 计数器设计 例子1 [打印本页]

作者: fangzhen    时间: 2008-11-20 15:10     标题: javacript 计数器设计 例子1

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>javacript 计数器</title>
</head>
<?php
$time =300;
if(isset($_GET['time'])) $time = (int)$_GET['time'];
?>
<script language="JavaScript" type="text/javascript">
var endsecond=<?php echo $time?>;
var num=0;
var endtime=0;
function showendtime() {
        num=num+1;
        endtime=endsecond-num;
        var fen=parseInt(endtime/60);
        var sec=endtime%60;
        var str1=fen+"分"+sec+"秒";
        jtime.innerText=str1;
        setTimeout("showendtime()", 1000);
}
if(endsecond>0) {
   setTimeout("showendtime()", 1000);
}

function stoptime() {
        window.location.href = "interval.php?time=<?php echo $time?>";
}
</script>
<body>
<div id="jtime" onclick="stoptime()"></div>
<div ></div>
</body>
</html>




欢迎光临 PHP开发笔记 (http://phpvi.com/) Powered by Discuz! 6.1.0