<p>该代码有语法错误,需要进行修改:</p>
<ol>
<li>第16行 <code>getdate()</code> 函数拼写错误,应更正为 <code>getDate()</code>。</li>
<li>第24行代码有语法错误,缺少变量名,应为 <code>var sw</code>。</li>
<li>第29行代码语法错误,应为 <code>else if(ds&gt;12&amp;&amp;ds&lt;18){</code>。</li>
<li>第32行代码语法错误,应为 <code>else if(ds==6){</code>。</li>
</ol>
<p>修改后的代码如下:</p>
<!DOCTYPE html>
<html>
  <head>
	<meta charset="utf-8" name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1, user-scalable=no">
	<title>WebCat</title>
    <style>
    h3{
      text-align:center;
      }
    </style>
  </head>
  <body>	
	<h3>现在是北京时间:2023年6月16号晚上9:03:45</h3>
 <script>
 var i = new Date();
 alert("现在是北京时间:"+i.getFullYear()+"年"+getDate()+"月"+i.getDate()+"号"+getHours()+":");
 function getDate(){
     var po = [1,2,3,4,5,6,7,8,9,10,11,12];
     return po[i.getMonth()];
     }
 function getHours(){
     var po = [12,1,2,3,4,5,6,7,8,9,10,11,"半夜","凌晨","上午","中午","下午","傍晚","晚上"];
     var ds = i.getHours();
     var sw;
     if(ds == 0){
       sw = 12;
     }else if(ds > 0 && ds < 6){
       sw = 13;
     }else if(ds >= 6 && ds < 12){
       sw = 14;
     }else if(ds == 12){
       sw = 15;
     }else if(ds > 12 && ds < 18){
       sw = 16;
     }else if(ds == 18){
       sw = 17;
     }else if(ds > 18 && ds <= 23){
       sw = 18;
     }
     if(ds >= 12){
       ds = ds - 12;
     }
     return po[sw] + po[ds];
 }
 </script>
  </body>
</html
!DOCTYPE htmlhtml head	meta charset=utf-8 name=viewport content=width=device-width initial-scale=1 maximum-scale=1 user-scalable=no	titleWebCattitle style h3 text-aligncenter; sty

原文地址: https://www.cveoy.top/t/topic/hc0Y 著作权归作者所有。请勿转载和采集!

免费AI点我,无需注册和登录