我整个晚上都在纠结这个问题。
http://codepen.io/Casfan/pen/xOPKYE?editors=1111
我有一份物品清单
<ul> <li><span class="glyphicon glyphicon-flag" aria-hidden="true"></span> Blackwell Grange <time datetime="2016-07-23">23/07/2016</time> 12:30 *Prudhoe, Garesfield <a href="#" class ="datelink">THIS LINK SHOULD SHOW NOW</a>
<li><span class="glyphicon glyphicon-flag" aria-hidden="true"></span> Blackwell Grange <time datetime="2016-07-23">23/07/2016</time> 12:30 *Prudhoe, Garesfield <a href="#" class ="datelink">THIS LINK SHOULD SHOW NOW</a>
<a class="resultdate" id="tempresults" href='https://www.dropbox.com/sh/4gxqq4pej9c58oa/AAChi69GfE1Mf58auVeV5jf9a?dl=0'>THIS LINK SHOULD SHOW IF THE DATE IN DATE TIME IS SET TO THE PAST</a></li>
... etc
</ul>css
.datelink {
display:none;
}
.resultdate {
display:none;
}所以链接一开始是隐藏的,然后使用coffeescript,因为我是在RoR中这样做的,我有
$(document).ready ->
now = undefined
now = new Date
$('ul li time').each ->
dateTime = Date.parse($(this).attr('datetime'))
startdate = new Date(dateTime)
startdate.setDate startdate.getDate() - 14
enddate = new Date(dateTime)
enddate.setDate enddate.getDate() - 2
if now > startdate and now < enddate
$(this).next('a.datelink').show()
return
$('ul li time').each ->
dateTime = Date.parse($(this).attr('datetime'))
fixturedate = new Date(dateTime)
if now > fixturedate
$( "#tempresults" ).show()
return
return我在html中使用时间日期属性来设置灯具的日期,当我们在两个日期之间时,其中的第一个函数工作并显示链接。第二个函数,我想显示另一个链接,如果日期是过去的,那么只有一个列表项有这个类或id。
我认为当我只有一个函数时,逻辑是有效的,当我有两个函数时,最下面的那个不起作用。我尝试将其组合到一个函数中,但只有顶部的if语句有效。我尝试过使用$(this).next('a.resultdate').show()
我做错了什么?
https://stackoverflow.com/questions/38315870
复制相似问题