0

我真的很少有编程经验,但是,我愿意学习 - 我找到了倒计时时钟的代码,但文本没有按照我想要的方式排列。我希望它是:

         Only
       **1905**
Days Until June 1, 2018

然后将其全部居中。它居中,但计数器的最后一部分会自行堆叠。这是我正在使用的代码:

<center>
    <font color="Turquoise"size="5">
    <b>
    Only
    <font color="red"size="6">
    <SCRIPT LANGUAGE = "JavaScript">
        var now = new Date();
        // set this value to the countdown date.
        var then = new Date("June 1, 2018");
        var gap = then.getTime() - now.getTime();
        gap = Math.floor(gap / (1000 * 60 * 60 * 24));
        document.write(gap); 
    </SCRIPT>
    <font color="turquoise"size="5">
    Days Until 
    <font color="6600FF"size="5">
    <br>June 1, 2018 </b>
</center>
</font>
4

2 回答 2

2

您发现的那段代码显然很古老,但问题在于<br>该行的标签:

<br>June 1, 2018 </b>

这是一个 HTML 换行符。删除它,线路不会中断。

于 2013-03-14T00:21:45.577 回答
0

尝试这个:

<div style='text-align: center'>
    <div>Only</div>
    <div><span>**</span><span id='countdown'></span><span>**</span></div>
    <div><span>Days Until </span><span id='targetDate'></span></div>
</div>
<script type='text/javascript'>
    var countNode, targetDateNode, now, then, gap, monthNames;
monthNames = [];
monthNames.push('January');
monthNames.push('February');
monthNames.push('March');
monthNames.push('April');
monthNames.push('May');
monthNames.push('June');
monthNames.push('July');
monthNames.push('August');
monthNames.push('September');
monthNames.push('October');
monthNames.push('November');
monthNames.push('December');
countNode = document.getElementById('countdown');
targetDateNode = document.getElementById('targetDate');

now = new Date();
// set this value to the countdown date.
then = new Date('June 1, 2018');
gap = then.getTime() - now.getTime();
gap = Math.floor(gap / (1000 * 60 * 60 * 24));
countNode.innerHTML = gap;
targetDateNode.innerHTML = monthNames[then.getMonth()] + ' ' + then.getDay() + ', ' + then.getFullYear();
</script>
于 2013-03-14T00:46:10.680 回答