用 ‘dreamweaver’ 的工具 的编写 HTML 代码、用 javascript 实现 页面动态的显示时 间的代码
代码:
<HTML>
<head>
<title></title> <script>
function getDateDemo(){
//分别获取年、月、日、时、分、秒
var myDate = new Date()
var year = myDate.getFullYear()
var month = myDate.getMonth() + 1
var date = myDate.getDate()
var hours = myDate.getHours()
var minutes = myDate.getMinutes()
var seconds = myDate.getSeconds()
//月份的显示为两位数字如09月
if(month < 10 ){
month = "0" + month
}
if(date < 10 ){
date = "0" + date
}
//时间拼接
var dateTime = year + "年" + month + "月" + date + "日" + hours + "时" + minutes + "分" +
seconds + "秒"
//document.write(dateTime)//打印当前时间
var divNode = document.getElementById("time")
divNode.innerHTML = dateTime
}
window.setInterval("getDateDemo()",1000)//每隔1秒,调用一次getDateDemo()
</script>
</head>
<Body>
<DIV id="time"></DIV>
</Body>
</HTML>
---------------------------------------------------------------
<div id="linkweb">
</div>
<script>setInterval("linkweb.innerHTML=new Date().toLocaleString()+' 星期'+'日一二三四五六'.charAt(new Date().getDay())",1000)
</script>
纯HTML不可能实现,可以借助于JAVASCRIPT的 setInterval或setTimeout来定时执行一个更新文本的函数来实现。给你一段代码:<!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>
<title>new document </title>
<meta name="generator" content="editplus" />
<meta name="author" content="" />
<meta name="keywords" content="" />
<meta name="description" content="" />
<script type="text/javascript">
<!--
setInterval("showTime()",1000)
function showTime()
{
var wk = ["星期日","星期一","星期二","星期三","星期四","星期五","星期六"]
var date = new Date()
var msg = "今天是:" + date.getFullYear()+"年"
msg += date.getMonth()+1 +"月"
msg += date.getDate() + "日"
msg += wk[date.getDay()]+" "
msg += date.getHours()+":" + date.getMinutes()+":"+date.getSeconds()
document.getElementById("time").innerText = msg
}
//-->
</script>
</head>
<body>
<span id="time"></span>
</body>
</html>
安装如下步骤 *** 作:
1.在电脑磁盘空白出右键-新建,点击文档
2.将文档命名为index,用记事本打开
3.
写入一下代码,如图:
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html"/>
<title>时间的动态显示</title>
</head>
<body>
</body>
</html>
4.在html头部写入获取时间的代码,如图
<script language="javascript">
var t = null
t = setTimeout(time,1000)//开始执行
function time()
{
clearTimeout(t)//清除定时器
dt = new Date()
var y=dt.getYear()+1900
var mm=dt.getMonth()+1
var d=dt.getDate()
var weekday=["星期日","星期一","星期二","星期三","星期四","星期五","星期六"]
var day=dt.getDay()
var h=dt.getHours()
var m=dt.getMinutes()
var s=dt.getSeconds()
if(h<10){h="0"+h}
if(m<10){m="0"+m}
if(s<10){s="0"+s}
document.getElementById("timeShow").innerHTML = "现在的时间为:"+y+"年"+mm+"月"+d+"日"+weekday[day]+"
"+h+":"+m+":"+s+""
t = setTimeout(time,1000)//设定定时器,循环执行
}
</script>
5.
在内容部分写入div标签,并附上ID,用来加载时间的载体。如图:
<div id="timeShow" class="time1"></div>
6.在头部写入div的样式如图,并保存
<style>
.time1{width:100%height:50pxbackground:#FFF000line-height:50pxtext-align:center}
</style>
7.保存后,将文件后缀命名为html。点击查看,勾选文件扩展名
8.文件后缀命名由txt改为html
9.使用浏览器打开文件
10.可以看到编写的文件,网页显示时间了
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)