我的编程经验非常少,但是,我愿意学习 - 我找到了倒计时时钟的代码,但文字没有按照我想要的方式排列。我希望它是:
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>
答案 0 :(得分:2)
您发现它的代码显然很古老,但问题是该行的<br>
标记:
<br>June 1, 2018 </b>
这是一个HTML换行符。删除它,线不会破裂。
答案 1 :(得分: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>