日期:2014-05-16  浏览次数:20621 次

关于JavaScirpt,我有疑问,请您帮助。
最近小弟我出学JS在调程序时遇到了麻烦,请各位前辈专家指点。
以下是有问题的程序:
<html   >
<head>
<title> Date对象 </title>
<script   language= "javascript ">
function   disptime()
{
var   now=new   Date();
var   hour=now.getHours();
var   mins=now.getMinutes();
var   sed=now.getSeconds();
if(hour> 0&&hour <=12)
document.write( "上午好! ");
if(hour> 12&&hour <=18)
document.write( "下午好! ");
if(hour> 18   &&   hour <24)
document.write( "晚上好! ");
document.myform.myclock.value= "现在时间: "+hour+ ": "+mins+ ": "+sed+ "   ";
var   myTime=setTimeout( "disptime() ",1000);
}
</script>
</head>

<body   onload= "disptime() ">
<form   name= "myform ">
<div   align= "center ">
<input   type= "text "   name= "myclock "   value= " "   >
</div>
</form>
</body>
</html>

编译器回应说document.myform.myclock.value对象为空,为什么呢?
请您指点,谢谢,谢谢!

------解决方案--------------------
<html >
<head>
<title> Date对象 </title>
<script language= "javascript ">
function disptime()
{
var now=new Date();
var hour=now.getHours();
var mins=now.getMinutes();
var sed=now.getSeconds();
if(hour> 0&&hour <=12)
document.myform.t1.value= "上午好! ";
else if(hour> 12&&hour <=18)
document.myform.t1.value= "下午好! ";
else if(hour> 18 && hour <=24)
document.myform.t1.value= "晚上好! ";
document.myform.myclock.value= "现在时间: "+(hour> =10? " ": "0 ")+hour+(mins> =10? ": ": ":0 ")+mins+(sed> =10? ": ": ":0 ")+sed+ " ";
setTimeout( "disptime() ",1000);
}
</script>
</head>
<body onload= "disptime() ">
<form name= "myform ">
<div align= "center ">
<input type= "text " name= "t1 " value= " " >
<input type= "text " name= "myclock " value= " " >
</div>
</form>
</body>
</html>