我希望将某些特定内容添加到我的网站,以便在一年中的某些时候自动添加?我应该在代码中添加些什么才能使其成为可能?
这是我要编辑的代码:
<div class="event-table">
<ul class="content-box-list events" data-id="314324">
<li data-id="701207" class="first">
<span class="date" data-unix-date="1556078400" data-time="">Wed, Apr<br><strong>24</strong></span>
<span class="title">8th Grade Class Fundraising Meeting</span>
<span class="see-details">See Details</span>
</li>
<li data-id="735125">
<span class="date" data-unix-date="1556769600" data-time="">Thu, May<br><strong>2</strong></span>
<span class="title">Spring Band Concert Dress Rehearsal</span>
<span class="see-details">See Details</span>
</li>
<li data-id="735135">
<span class="date" data-unix-date="1556769600" data-time="">Thu, May<br><strong>2</strong></span>
<span class="title">Spring Band Concert </span>
<span class="see-details">See Details</span>
</li>
<li data-id="815524">
<span class="date" data-unix-date="1557720000" data-time="">Mon, May<br><strong>13</strong></span>
<span class="title">Board of Education Meeting</span>
<span class="see-details">See Details</span>
</li>
<li data-id="698413" class="last">
<span class="date" data-unix-date="1557892800" data-time="">Wed, May<br><strong>15</strong></span>
<span class="title">PTO Meeting</span>
<span class="see-details">See Details</span>
</li>
</ul>
</div>
答案 0 :(得分:0)
如果我正确理解了您的问题,您想在特定日期将内容添加到您的网站,则可以使用Javascript实现这一点,方法是确定当前日期,然后编写一些if子句以在该日期做某件事符合条件,例如,如果您想今天显示一条消息,则可以这样做:
var today = new Date();
var dd = String(today.getDate()).padStart(2, '0');
var mm = String(today.getMonth() + 1).padStart(2, '0'); //January is 0!
var yyyy = today.getFullYear();
today = mm + '/' + dd + '/' + yyyy;
if(today == '04/19/2019') {
alert('do this');
$('.yourClass').show(); //show content
$('.yourOtherClass').hide() //hide content
}
编辑:如果需要更具体,还可以确定星期几和一天中的时间。