如何在一行中显示此代码?它目前显示一行在另一行之上,它正在抛弃我的格式。如果可能的话,我希望所有人都在一行。我不是编码方面的专家,如此明确地解释如何做到这一点将不胜感激。
<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 :(得分: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>