HTML的动态时间如何做…

HTML的动态时间如何做…,第1张

纯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>

在<head></head>之间插入JAVASCRIPT代码

<script language="JavaScript" type="text/javascript">

function showTime(){

var mytime=new Date()

var h=mytime.getHours()

var m=mytime.getMinutes()

var s=mytime.getSeconds()

if(h<10) h="0"+h

if(m<10) m="0"+m

if(s<10) s="0"+s

word.innerHTML=h+":"+m+":"+s

setTimeout("showTime()",1000)

}

function MM_jumpMenu(targ,selObj,restore){ //v3.0

eval(targ+".location='"+selObj.options[selObj.selectedIndex].value+"'")

if (restore) selObj.selectedIndex=0

}

function MM_findObj(n, d) { //v4.01

var p,i,x if(!d) d=documentif((p=n.indexOf("?"))>0&&parent.frames.length) {

d=parent.frames[n.substring(p+1)].documentn=n.substring(0,p)}

if(!(x=d[n])&&d.all) x=d.all[n]for (i=0!x&&i<d.forms.lengthi++) x=d.forms[i][n]

for(i=0!x&&d.layers&&i<d.layers.lengthi++) x=MM_findObj(n,d.layers[i].document)

if(!x &&d.getElementById) x=d.getElementById(n)return x

}

function MM_jumpMenuGo(selName,targ,restore){ //v3.0

var selObj = MM_findObj(selName)if (selObj) MM_jumpMenu(targ,selObj,restore)

}

</script>

然后在你想要显示的地方插入代码

<div class="STYLE3" id="word"></div>


欢迎分享,转载请注明来源:内存溢出

原文地址: http://outofmemory.cn/bake/11720749.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2023-05-18
下一篇 2023-05-18

发表评论

登录后才能评论

评论列表(0条)

保存