JS里面动态时间
来源:百度知道 编辑:UC知道 时间:2024/06/06 15:25:04
代码如下
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
<title>无标题文档</title>
<script language="javascript">
function time(){
var today=new Date()
var h=today.getHours()
var m=today.getMinutes()
var s=today.getSeconds()
document.writeln( "现在的时间为:"+h+"时"+m+"分"+s+"秒");
var t=setTimeout('time()',500);
}
</script>
</head>
<body onload="time()">
</body>
</html>
为什么时间不能刷新,提示缺少对象。。
怎么改啊。。。
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
<title>无标题文档</title>
<script language="javascript">
function time(){
var today=new Date()
var h=today.getHours()
var m=today.getMinutes()
var s=today.getSeconds()
document.writeln( "现在的时间为:"+h+"时"+m+"分"+s+"秒");
var t=setTimeout('time()',500);
}
</script>
</head>
<body onload="time()">
</body>
</html>
为什么时间不能刷新,提示缺少对象。。
怎么改啊。。。
//参考如下代码:
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>无标题文档</title>
<script language="javascript">
var t = null;
t = setTimeout(time,1000);//开始执行
function time()
{
clearTimeout(t);//清除定时器
dt = new Date();
var h=dt.getHours();
var m=dt.getMinutes();
var s=dt.getSeconds(