JavaScript案例三:动态显示时间

时间:2024-08-24 19:05:50

用JavaScript实现在页面上动态的显示时间

<!DOCTYPE html>
<html>
<head>
<title>JavaScript动态显示时间</title>
<meta http-equiv="content-type" content="text/html; charset=UTF-8">
<script type="text/javascript" >
//写入时间
function func()
{
var date=new Date();
var s=document.getElementById("sid");
s.innerHTML=date.toLocaleString();
}
//定时器
setInterval("func()", 1000);
</script>
</head>
<body>
<span id="sid"></span>
</body>
</html>