<html> <head> <meta http-equiv="Content-Type" content="text/html; charset=gb2312"> <title>无标题文档</title> </head> <body> <INPUT name=aa size="49"> <script language="JavaScript"> <!-- window.setInterval("myclock()",1000);function myclock() { var thetime=new Date(); var theyear=thetime.getFullYear(); var themonth=thetime.getMonth(); var theday=thetime.getDate(); var theweekday=thetime.getDay(); var thehour=thetime.getHours(); var theminute=thetime.getMinutes(); var thesecond=thetime.getSeconds(); var theafternoon="A.M"; var abc= new Array(7) abc[0]="Sunday"; abc[1]="monday"; abc[2]="tuesday"; abc[3]="wednesday"; abc[4]="thursday"; abc[5]="friday"; abc[6]="saturday"; if(thehour>12) {thehour-=12; theafternoon="P.M";} themonth++; aa.value=abc[theweekday]+"/"+theyear+"/"+themonth+"/"+theday+" "+thehour+"/"+theminute+"/"+thesecond+" Whether it is"+theafternoon; }
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
<title>无标题文档</title>
</head>
<body>
<INPUT name=aa size="49">
<script language="JavaScript">
<!--
window.setInterval("myclock()",1000);function myclock()
{
var thetime=new Date();
var theyear=thetime.getFullYear();
var themonth=thetime.getMonth();
var theday=thetime.getDate();
var theweekday=thetime.getDay();
var thehour=thetime.getHours();
var theminute=thetime.getMinutes();
var thesecond=thetime.getSeconds();
var theafternoon="A.M";
var abc= new Array(7)
abc[0]="Sunday";
abc[1]="monday";
abc[2]="tuesday";
abc[3]="wednesday";
abc[4]="thursday";
abc[5]="friday";
abc[6]="saturday";
if(thehour>12)
{thehour-=12;
theafternoon="P.M";}
themonth++;
aa.value=abc[theweekday]+"/"+theyear+"/"+themonth+"/"+theday+" "+thehour+"/"+theminute+"/"+thesecond+" Whether it is"+theafternoon;
}
window.setInterval("myclock()",1000);
//-->
</script>
</body>
</html>
为什么用document.write写在页面里不可以,而像你那样aa.value就可以,还有,这个aa.value是什么啊?
此外可以用这样的方法,在页面中定义<p id="aa"></p>
把
aa.value=abc[theweekday]+"/"+theyear+"/"+themonth+"/"+theday+" "+thehour+"/"+theminute+"/"+thesecond+" Whether it is"+theafternoon;
改为
value=abc[theweekday]+"/"+theyear+"/"+themonth+"/"+theday+" "+thehour+"/"+theminute+"/"+thesecond+" Whether it is"+theafternoon;
document.all("aa").innerText=value;又你定义的显示不符合规范,我是这样定义的
value=abc[theweekday]
+" "+theyear+"/"+
((themonth>9)?themonth:("0"+themonth))+"/"+
((theday>9)?theday:("0"+theday))+" "+
((thehour>9)?thehour:("0"+thehour))+":"+
((theminute>9)?theminute:("0"+theminute))+":"+
((thesecond>9)?thesecond:("0"+thesecond))+" Whether it is"+theafternoon;