2017-06-20 89 views
0

如何让这段代码在一行中显示?它目前显示一条线在另一条线的上方,它将丢弃我的格式。如果可能我希望它全部在一行中。我不是编码专家,所以如何做到这一点的明确解释将不胜感激。将脚本从垂直改为水平?

<table cellpadding="0" cellspacing="0"> 
 
    <tr> 
 
     <td class="company-homepagetime" valign="top"> 
 
      <script type="text/javascript"> 
 
       function getClockTime() 
 
       { 
 
        var now = new Date(); 
 
        var hour = now.getHours(); 
 
        var minute = now.getMinutes(); 
 
        var second = now.getSeconds(); 
 
        var ap = "<span class='company-homepagetime-ampm'>AM</span>"; 
 
        if (hour > 11) { ap = "<span class='company-homepagetime-ampm'>PM</span>";} 
 
        if (hour > 12) { hour = hour - 12;  } 
 
        if (hour == 0) { hour = 12;    } 
 
        if (minute < 10) { minute = "0" + minute; } 
 
        if (second < 10) { second = "0" + second; } 
 
        var timeString = hour + 
 
         ':' + 
 
         minute + 
 
         " " + 
 
         ap; 
 
        return timeString; 
 
       } // function getClockTime() 
 
        var clockTime = getClockTime(); 
 
        document.write(clockTime); 
 
      </script> 
 
     </td> 
 
    </tr> 
 
    <tr> 
 
     <td class="company-homepagedate" valign="top"> 
 
      <script type="text/javascript"> 
 
       var months=new Array(13); 
 
       months[1]="January"; 
 
       months[2]="Febuary"; 
 
       months[3]="March"; 
 
       months[4]="April"; 
 
       months[5]="May"; 
 
       months[6]="June"; 
 
       months[7]="July"; 
 
       months[8]="August"; 
 
       months[9]="September"; 
 
       months[10]="October"; 
 
       months[11]="November"; 
 
       months[12]="December"; 
 
       var day=new Date(); 
 
       var lmonth=months[day.getMonth() + 1]; 
 
       var date=day.getDate(); 
 
       var year = day.getFullYear(); 
 
       document.write(lmonth + " " + date + ", " + year); 
 
      </script> 
 
     </td> 
 
    </tr> 
 
</table>

+0

就拿这部分出了中间的,如下图所示。 '' – Cooper

回答

0

只是把它放在同一个TD是这样的:

<!DOCTYPE html> 
<html> 
    <head> 
    <base target="_top"> 
    </head> 
    <body> 
    <table cellpadding="0" cellspacing="0" width="100%"> 
    <tr> 
     <td class="company-homepagetime" valign="top"> 
      <script type="text/javascript"> 
       function getClockTime() 
       { 
        var now = new Date(); 
        var hour = now.getHours(); 
        var minute = now.getMinutes(); 
        var second = now.getSeconds(); 
        var ap = "<span class='company-homepagetime-ampm'>AM</span>"; 
        if (hour > 11) { ap = "<span class='company-homepagetime-ampm'>PM</span>";} 
        if (hour > 12) { hour = hour - 12;  } 
        if (hour == 0) { hour = 12;    } 
        if (minute < 10) { minute = "0" + minute; } 
        if (second < 10) { second = "0" + second; } 
        var timeString = hour + 
         ':' + 
         minute + 
         " " + 
         ap; 
        return timeString; 
       } // function getClockTime() 
        var clockTime = getClockTime(); 
        document.write(clockTime); 
      </script> 
      <script type="text/javascript"> 
       var months=new Array(13); 
       months[1]="January"; 
       months[2]="Febuary"; 
       months[3]="March"; 
       months[4]="April"; 
       months[5]="May"; 
       months[6]="June"; 
       months[7]="July"; 
       months[8]="August"; 
       months[9]="September"; 
       months[10]="October"; 
       months[11]="November"; 
       months[12]="December"; 
       var day=new Date(); 
       var lmonth=months[day.getMonth() + 1]; 
       var date=day.getDate(); 
       var year = day.getFullYear(); 
       document.write(lmonth + " " + date + ", " + year); 
      </script> 
     </td> 
    </tr> 
</table> 
    </body> 
</html> 

enter image description here