写了一个js的时钟演示方法,但是时间就是固定的,不会动!请各位大侠帮忙看下!
<scriptlanguage=javascript>functiondisptime(){vartime=newDate();varhh=time.getHours()...
<script language=javascript>
function disptime(){
var time=new Date();
var hh=time.getHours();
var ss=time.getSeconds();
var mm=time.getMinutes();
var day=time.getDay();
var dn="AM";
if(hh>12)
dn="PM";
hh=hh-12;
if(mm<0)
mm="0"+mm;
if(ss<0)
ss="0"+ss;
switch(day){
case 0:
day="星期一";
break;
case 1:
day="星期二";
break;
case 2:
day="星期三";
break;
case 3:
day="星期四";
break;
case 4:
day="星期五";
break;
case 5:
day="星期六";
break;
default:
day="星期天";
break;}
document.writeln("今天是"+time.getYear()+"年"+(time.getMonth()+1)+"月"+time.getDate()+"日"+hh+"点"+mm+"分"+ss+"秒"+" "+dn+" "+day);
var mytime=setTimeout('disptime()',1000);
}
</script>
</head>
<body onload="disptime()">
</body>
</html> 展开
function disptime(){
var time=new Date();
var hh=time.getHours();
var ss=time.getSeconds();
var mm=time.getMinutes();
var day=time.getDay();
var dn="AM";
if(hh>12)
dn="PM";
hh=hh-12;
if(mm<0)
mm="0"+mm;
if(ss<0)
ss="0"+ss;
switch(day){
case 0:
day="星期一";
break;
case 1:
day="星期二";
break;
case 2:
day="星期三";
break;
case 3:
day="星期四";
break;
case 4:
day="星期五";
break;
case 5:
day="星期六";
break;
default:
day="星期天";
break;}
document.writeln("今天是"+time.getYear()+"年"+(time.getMonth()+1)+"月"+time.getDate()+"日"+hh+"点"+mm+"分"+ss+"秒"+" "+dn+" "+day);
var mytime=setTimeout('disptime()',1000);
}
</script>
</head>
<body onload="disptime()">
</body>
</html> 展开
展开全部
在你的基础上改的,你看看,能明白么
<script language=javascript>
function disptime(){
var time=new Date();
var hh=time.getHours();
var ss=time.getSeconds();
var mm=time.getMinutes();
var day=time.getDay();
var dn="AM";
if(hh>12)
dn="PM";
hh=hh-12;
if(mm<0)
mm="0"+mm;
if(ss<0)
ss="0"+ss;
switch(day){
case 0:
day="星期一";
break;
case 1:
day="星期二";
break;
case 2:
day="星期三";
break;
case 3:
day="星期四";
break;
case 4:
day="星期五";
break;
case 5:
day="星期六";
break;
default:
day="星期天";
break;}
//document.writeln("今天是"+time.getYear()+"年"+(time.getMonth()+1)+"月"+time.getDate()+"日"+hh+"点"+mm+"分"+ss+"秒"+" "+dn+" "+day);
document.getElementById("y").innerHTML=time.getYear();
document.getElementById("m").innerHTML=time.getMonth()+1;
document.getElementById("d").innerHTML=time.getDate();
document.getElementById("h").innerHTML=hh;
document.getElementById("mi").innerHTML=mm;
document.getElementById("s").innerHTML=ss;
document.getElementById("day").innerHTML=" "+dn+" "+day;
var mytime=setTimeout('disptime()',1000);
}
</script>
</head>
<body onload="disptime()">
今天是<span id="y"></span>年<span id="m"></span>月<span id="d"></span>日<span id="h"></span>点<span id="mi"></span>分<span id="s"></span>秒<span id="day"></span>
</body>
</html>
展开全部
<script language=javascript>
function disptime(){
var time=new Date();
var hh=time.getHours();
var ss=time.getSeconds();
var mm=time.getMinutes();
var day=time.getDay();
var dn="AM";
if(hh>12)
dn="PM";
hh=hh-12;
if(mm<0)
mm="0"+mm;
if(ss<0)
ss="0"+ss;
switch(day){
case 0:
day="星期一";
break;
case 1:
day="星期二";
break;
case 2:
day="星期三";
break;
case 3:
day="星期四";
break;
case 4:
day="星期五";
break;
case 5:
day="星期六";
break;
default:
day="星期天";
break;}
document.getElementById("time").innerText = "今天是"+time.getYear()+"年"+(time.getMonth()+1)+"月"+time.getDate()+"日"+hh+"点"+mm+"分"+ss+"秒"+" "+dn+" "+day;
var mytime=setTimeout('disptime()',1000);
}
</script>
</head>
<body onload="disptime()">
<div id="time"></div>
</body>
</html>
本回答被提问者采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
在 document.writeln..... 下面setTimeout之前加句话 document.close(); 试试
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询