前两天用JavaScript写了一个页面显示时间,结果怎么也显示不出来
希望高手能帮帮忙看看<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head><meta http-equiv="Content-Type" content="text/html; charset=gbk" />
  <title> text中的全时钟显示 </title>
  <script type="text/javascript">
  var timerID = null
  var timerRunning = false       //计时器运行标志全局变量
  function MakeArray(size){      //手工定义数组
      this.length = size;
  for(var i = 1; i<=size;i++){
    this[i]="";
  }
  return this;  }
function stopclock(){
      if(timerRunning)clearTimeout(timerID);  //取消时钟定时功能
  timerRunning = false;
  document.showform.start.disabled = false;  //设定按钮的可用性
  document.showform.stop.disabled = true;
}
function showtime(){
      var now = new Date();
  var year = new.getYear();
  var month = new.getMonth()+1;
  var date = new.getDate();
  var hours = new.getHours();
  var minutes = new.getMinutes();
  var seconds = new.getSeconds();
  var day = new.getDay();
  Day = new.getDay();
  Day[0]="星期天";
  Day[1]="星期一";
  Day[2]="星期二";
  Day[3]="星期三";
  Day[4]="星期四";
  Day[5]="星期五";
  Day[6]="星期六";
      var timeValue="";
  timeValue+=year+"年";
  timeValue+=((month<10)?"0":"")+month+"月";
  timeValue+=date+"日 ";
  timeValue+=(Day[day])+" ";
  timeValue+=(hours<12)?"上午":"下午";
  timeValue+=((hours<=12)?hours:hours-12);
  timeValue+=((minutes<10)?":0":":")+minutes;
  timeValue+=((seconds<10)?":0":":")+seconds;
  document.showform.timeshow.value = timeValue;  //执行实时全时间显示
  timerRunning = true;
}
 function startclock(){
   stopclock();
   showtime();
   document.showform.start.disabled=true;
   document.showform.stop.disbled=false;
 }
  </script>
 </head>
 <body bgColor = #fef4d9 onload=startclock()>
 <center><font color=red face=隶书 size=4>TEXT中全时钟显示</font><br />
 <form name="showfrom">
 <input type="text" name="timeshow"size=34 />
 <input type="button" name="start" value="启动" onClick="startclock();" />
 <input type="button" name="stop" value="停止" onClick="stopclock();" />
 </form>
 </center>
 </body>
</html>

解决方案 »

  1.   

    JS里获取时间用错了吧
    mydate=new Date();   
    myweekday=mydate.getDay();   
    mymonth=mydate.getMonth()+1;   
    myday= mydate.getDate();   
    year= mydate.getFullYear();
      

  2.   


    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    <html xmlns="http://www.w3.org/1999/xhtml">
    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
    <title> text中的全时钟显示 </title>
    <script type="text/javascript">
    var timerID = null
    var timerRunning = false //计时器运行标志全局变量
    function MakeArray(size){ //手工定义数组
    this.length = size;
    for(var i = 1; i<=size;i++){
    this[i]="";
    }
    return this;
    }
    function stopclock(){
    if(timerRunning)clearTimeout(timerID); //取消时钟定时功能
    timerRunning = false;
    document.all.start.disabled = false; //设定按钮的可用性
    document.all.stop.disabled = true;
    }
    function showtime(){
    var now = new Date();
    var year = now.getYear();
    var month = now.getMonth()+1;
    var date = now.getDate();
    var hours = now.getHours();
    var minutes = now.getMinutes();
    var seconds = now.getSeconds();
    var day = now.getDay();
    var Day=new Array();
    Day[0]="星期天";
    Day[1]="星期一";
    Day[2]="星期二";
    Day[3]="星期三";
    Day[4]="星期四";
    Day[5]="星期五";
    Day[6]="星期六";
    var timeValue="";
    timeValue+=year+"年";
    timeValue+=((month<10)?"0":"")+month+"月";
    timeValue+=date+"日 ";
    timeValue+=(Day[day])+" ";
    timeValue+=(hours<12)?"上午":"下午";
    timeValue+=((hours<=12)?hours:hours-12);
    timeValue+=((minutes<10)?":0":":")+minutes;
    timeValue+=((seconds<10)?":0":":")+seconds;
    document.all.timeshow.value = timeValue; //执行实时全时间显示
    timerRunning = true;
    }
    function startclock(){
    showtime();
    timerID=setInterval(showtime,1000)
    document.all.start.disabled=true;
    document.all.stop.disbled=false;
    }
    </script>
    </head>
    <body bgColor='#fef4d9' onload="startclock()">
    <center><font color=red face=隶书 size=4>TEXT中全时钟显示</font><br />
    <form name="showfrom">
    <input type="text" name="timeshow" size=34 />
    <input type="button" name="start" value="启动" onclick="startclock()"/>
    <input type="button" name="stop" value="停止" onclick="stopclock()"  />
    </form>
    </center>
    </body>
    </html>
      

  3.   


    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    <html xmlns="http://www.w3.org/1999/xhtml">
    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
    <title> text中的全时钟显示 </title>
    <script type="text/javascript">
    var timerID = null
    var timerRunning = false //计时器运行标志全局变量
    function MakeArray(size){ //手工定义数组
    this.length = size;
    for(var i = 1; i<=size;i++){
    this[i]="";
    }
    return this;
    }
    function stopclock(){
    clearInterval(timerID); //取消时钟定时功能
    document.all.start.disabled = false; //设定按钮的可用性
    document.all.stop.disabled = true;
    }
    function showtime(){
    var now = new Date();
    var year = now.getYear();
    var month = now.getMonth()+1;
    var date = now.getDate();
    var hours = now.getHours();
    var minutes = now.getMinutes();
    var seconds = now.getSeconds();
    var day = now.getDay();
    var Day=new Array();
    Day[0]="星期天";
    Day[1]="星期一";
    Day[2]="星期二";
    Day[3]="星期三";
    Day[4]="星期四";
    Day[5]="星期五";
    Day[6]="星期六";
    var timeValue="";
    timeValue+=year+"年";
    timeValue+=((month<10)?"0":"")+month+"月";
    timeValue+=date+"日 ";
    timeValue+=(Day[day])+" ";
    timeValue+=(hours<12)?"上午":"下午";
    timeValue+=((hours<=12)?hours:hours-12);
    timeValue+=((minutes<10)?":0":":")+minutes;
    timeValue+=((seconds<10)?":0":":")+seconds;
    document.all.timeshow.value = timeValue; //执行实时全时间显示
    }
    function startclock(){
    showtime();
    timerID=setInterval(showtime,1000)
    document.all.start.disabled=true;
    document.all.stop.disabled=false;
    }
    </script>
    </head>
    <body bgColor='#fef4d9' onload="startclock()">
    <center><font color=red face=隶书 size=4>TEXT中全时钟显示</font><br />
    <form name="showfrom">
    <input type="text" name="timeshow" size=34 />
    <input type="button" name="start" value="启动" onclick="startclock()"/>
    <input type="button" name="stop" value="停止" onclick="stopclock()"  />
    </form>
    </center>
    </body>
    </html>