实时显示时间,希望来个好心人帮帮忙?

有无大佬帮我看看代码改怎么写啊 (图是最后的效果,代码是我写的代码)

 

 

 

<!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>
<title>Window对象的setTimeout()定时器方法</title>

<script>
    function xssj()
    {
      var theDate=new Date()        
      xsk.value=theDate.getHours(); 
      fzk.value=theDate.getMinutes();
      miaok.value=theDate.getSeconds();
      setTimeout("xssj()",1000); // 函数自己调用自己,实现了无限循环 
    }        </script>
<style type="text/css">
           body {font-size: 36px;color: #CC3333;}
           .ys {font-size: 24px;color: #0000CC;}             
           .pic{position:relative;
                 width:2990px;
                 height:2000px;}
           .time{position:absolute;
                 top:80%;
                 right:80%; }
              </style>
           
</head>
<body onLoad="xssj()">
   <div class="pic">
      <img src="../Pictures/Saved Pictures/无标题.png">
      <div class="time">
现在时刻:
<input name="xsk" type="text" size="2" readonly="true" class="ys" border=0> 

<input name="fzk" type="text" size="2" class="ys">分
<input name="miaok" type="text" size="2" class="ys"> 秒</div>
</div>
</body>
</html>

<!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>
<title>Window对象的setTimeout()定时器方法</title>

<script>
    function xssj()
    {
        var days = ["日","一","二","三","四","五","六"];
        var theDate = new Date();
        var hh = theDate.getHours();
        var mm = theDate.getMinutes();
        var ss = theDate.getSeconds();
        var day = theDate.getDay();
        var date = theDate.getDate();
        var year = theDate.getFullYear();
        var month = theDate.getMonth() + 1;
        document.getElementById("text").innerHTML = year+"年"+month+"月"+date+"目<br>"+
        "星期"+days[day]+" "+
        (hh>=12?hh-12:hh)+":"+(mm>9?"":"0")+mm+":"+(ss>9?"":"0")+ss+" "+(hh>=12?"PM":"AM"); 
        setTimeout("xssj()",1000); // 函数自己调用自己,实现了无限循环 
    }        
</script>
<style type="text/css">
           body {font-size: 36px;color: #CC3333;}
           .ys {font-size: 24px;color: #0000CC;}             
           .pic{position:relative;
                 width:2990px;
                 height:2000px;}
           .time{position:absolute;
                 top:80%;
                 right:80%;
                 text-align: center;
                  }
              </style>
           
</head>
<body onLoad="xssj()">
   <div class="pic">
      <img src="../Pictures/Saved Pictures/无标题.png">
      <div class="time ys">
          今天是<br />
          <div id="text"></div>
      </div>
</div>
</body>
</html>

 

你这个只获取时分秒,星期日期都没有获取

<!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>
<title>Window对象的setTimeout()定时器方法</title>

<script>
    function xssj()
    {
	    var xsk = document.getElementById("xsk");
	    var fzk = document.getElementById("fzk");
	    var miaok = document.getElementById("miaok");
      var theDate=new Date(); 
      xsk.value=theDate.getHours(); 
      fzk.value=theDate.getMinutes();
      miaok.value=theDate.getSeconds();
      setTimeout("xssj()",1000); // 函数自己调用自己,实现了无限循环 
    }        
</script>
<style type="text/css">
           body {font-size: 36px;color: #CC3333;}
           .ys {font-size: 24px;color: #0000CC;}             
           .pic{position:relative;
                 width:2990px;
                 height:2000px;}
           .time{position:absolute;
                 top:80%;
                 right:80%; }
              </style>
           
</head>
<body onLoad="xssj()">
   <div class="pic">
      <img src="../Pictures/Saved Pictures/无标题.png">
      <div class="time">
现在时刻:
<input id="xsk" type="text" size="2" readonly="true" class="ys" border=0> 
时
<input id="fzk" type="text" size="2" class="ys">分
<input id="miaok" type="text" size="2" class="ys"> 秒</div>
</div>
</body>
</html>

 

您好,我是有问必答小助手,您的问题已经有小伙伴解答了,您看下是否解决,可以追评进行沟通哦~

如果有您比较满意的答案 / 帮您提供解决思路的答案,可以点击【采纳】按钮,给回答的小伙伴一些鼓励哦~~

ps:问答VIP仅需29元,即可享受5次/月 有问必答服务,了解详情>>>https://vip.csdn.net/askvip?utm_source=1146287632