当前位置:编程学习 > JSP >>

想在jsp页面中显示系统时间,请问以下代码存在什么问题,就是出不来,急!

<html> <head> <meta http-equiv="Content-Type" content="text/html; charset=gb2312" /> <title>显示时间</title> <script language="javascript"> function clockon(bgclock){ var now=new Date(); var year=now.getYear(); var month=now.getMonth(); var date=now.getDay(); var week; month=month+1; if(month<10) month="0"+month; if(date<10) date="0"+date; var arr_week=new Array("星期日","星期一","星期二","星期三","星期 四","星期五","星期六"); week=arr_week[day]; var time=""; time=year+"年"+month+"月"+date+"日"+week; if(document.all){ bgclock.innerHTML="  "+time; } var timer=setTimeout("clockon(bgclock)",0); } </script> </head> <body onLoad="clockon(bgclock)"> hello,the time is: <div id="bgclock" class="word_Green"></div> </body> </html>
补充:我用其他的代码解决啦,谢谢大家啦
追问:试过啦,不行啊
答案:if(document.all){
	     bgclock.innerHTML="  "+time;
	     }
修改为:
	     if(document.all){
	     document.all.bgclock.innerHTML="  "+time;
	     }
试试
其他:个人认为你的id  bgclock用的有问题,我没见过函数变量这么用的 错误的地方是在onLoad=clockon这里  bgclock不是这么传的 
把方法里的参数干掉
 function clockon(){
var bgclock=document.getElementById("bgclock");
	     var now=new Date();
	     var year=now.getYear();
	     var month=now.getMonth();
	     var date=now.getDay();
	     var week;
	     month=month+1;
	     if(month<10) month="0"+month;
	     if(date<10) date="0"+date;
	     var arr_week=new Array("星期日","星期一","星期二","星期三","星期

四","星期五","星期六");
	     week=arr_week[day];
	     var time="";
	     time=year+"年"+month+"月"+date+"日"+week;
	     if(document.all){
	     bgclock.innerHTML="  "+time;
	     }
	     var timer=setTimeout("clockon(bgclock)",0);
	   }
	</script>

上一个:请详细说明 .net asp php jsp每一个的运行环境!
下一个:如何将html文件转化成jsp文件?

CopyRight © 2022 站长资源库 编程知识问答 zzzyk.com All Rights Reserved
部分文章来自网络,