我想在网页标题内显示当前系统日期减去7天。
<h1>Is this article older than (7 days prior today's date)</h1>
如何实现与元素内嵌显示?
谢谢。
答案 0 :(得分:0)
使用javascript Date
对象。请注意,月份索引基于0 ...
var d = new Date();
d.setDate(d.getDate() - 7);
document.getElementById('heading').innerHTML = "Is this article older than "+(d.getMonth() + 1)+"/"+d.getDate()+"/"+d.getFullYear();
<h1 id='heading'></h1>