求解 jsp一问
程序代码:
<html>
<head>
<title>
date
</title>
<style>
div{
margin-left:16%;
padding-top:16%;
width:1000px;
height:400px;
font-size:100px;
color:336699;
font-family:Gulim;
display:block;
}
</style>
<script type="text/javascript">
function timedCount(){
var d=new Date();
var y=d.getYear();
var m=d.getMonth();
var d=d.getDay();
var h=d.getHours();
var m=d.getMinutes();
var s=d.getSeconds()
m = judge(m);
d = judge(d);
h = judge(h);
m = judge(m);
s = judge(s);
divdate.innerHTML=y+"-"+m+"-"+d+" "+h+":"+m+":"+s;
var timer = setTimeout("timedCount()",1000)
}
function judge(a){
if(a<10){
a="0"+a;
}
return a;
}
</script>
</head>
<body onload="timedCount()">
<form>
<div id="divdate"></div>
</form>
</body>
</html>
以上运行时提示:var h=d.getHours();var m=d.getMinutes();var s=d.getSeconds()没有该方法或属性。<head>
<title>
date
</title>
<style>
div{
margin-left:16%;
padding-top:16%;
width:1000px;
height:400px;
font-size:100px;
color:336699;
font-family:Gulim;
display:block;
}
</style>
<script type="text/javascript">
function timedCount(){
var d=new Date();
var y=d.getYear();
var m=d.getMonth();
var d=d.getDay();
var h=d.getHours();
var m=d.getMinutes();
var s=d.getSeconds()
m = judge(m);
d = judge(d);
h = judge(h);
m = judge(m);
s = judge(s);
divdate.innerHTML=y+"-"+m+"-"+d+" "+h+":"+m+":"+s;
var timer = setTimeout("timedCount()",1000)
}
function judge(a){
if(a<10){
a="0"+a;
}
return a;
}
</script>
</head>
<body onload="timedCount()">
<form>
<div id="divdate"></div>
</form>
</body>
</html>
另外,将该三行注释,并且只输出日期,与系统时间不符合 2010-05-14 输出为2010-04-05
求解~~~~~
搜索更多相关主题的帖子:
jsp 求解
----------------解决方案--------------------------------------------------------
document.getElementById("outMsg").innerHTML = " 今天是"+new Date().getFullYear()+"年"+(new Date().getMonth()+1)+"月"+new Date().getDate()+"日 "+week;
参照我的。。
----------------解决方案--------------------------------------------------------
主要时间 而问题主要不是日期
----------------解决方案--------------------------------------------------------
你写的这段问题比较多,我用红色表出,改后就可以运行了。
var d=new Date();
var y=d.getYear();
var m=d.getMonth() + 1; //这里其实在JS和JAVA中1月是0,以此类推,所以这里为了和真实的月一致,应该加1.
var d=d.getDay(); //获得天是用getDate().还有这里的d和前面定义的变量重名了,改为:var d1 = d.getDate();
var h=d.getHours();
var m=d.getMinutes(); //又一次与前面定义的变量重名了,改为: var m1 = d.getMinutes();
var s=d.getSeconds()
m = judge(m);
d1 = judge(d1); //与上面的修改保持一致。
h = judge(h);
m1 = judge(m1); //与上面的修改保持一致。
s = judge(s);
divdate.innerHTML=y+"-"+m+"-"+d1+" "+h+":"+m1+":"+s; //与上面的修改保持一致。
var timer = setTimeout("timedCount()",1000); //定义这个timer没有必要,直接写成:setTimeout("timedCount()",1000);
应该仔细学习下。
[ 本帖最后由 baifenghan 于 2010-5-16 02:48 编辑 ]
----------------解决方案--------------------------------------------------------