Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/447.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 根据日期更改链接_Javascript_Jquery_Css_Ruby On Rails_Coffeescript - Fatal编程技术网

Javascript 根据日期更改链接

Javascript 根据日期更改链接,javascript,jquery,css,ruby-on-rails,coffeescript,Javascript,Jquery,Css,Ruby On Rails,Coffeescript,我整个晚上都在为这件事苦苦挣扎 我有一份物品清单 <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

我整个晚上都在为这件事苦苦挣扎

我有一份物品清单

  <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>
所以链接一开始是隐藏的,然后使用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
$(文档).ready->
现在=未定义
现在=新日期
$('ul li time')。每个->
dateTime=Date.parse($(this.attr('dateTime'))
startdate=新日期(dateTime)
startdate.setDate startdate.getDate()-14
enddate=新日期(日期时间)
enddate.setDate enddate.getDate()-2
如果现在>开始日期,现在<结束日期
$(this.next('a.datelink').show()
返回
$('ul li time')。每个->
dateTime=Date.parse($(this.attr('dateTime'))
fixturedate=新日期(日期时间)
如果现在>固定日期
$(“#tempresults”).show()
返回
返回
我在html中使用了一个time-datetime-atribute来设置设备的日期 其中的第一个函数在两个日期之间工作并显示链接。 第二个函数我想显示另一个带有resultdate类或tempresults id的链接,如果日期是过去的,则只有一个列表项具有此类或id

我认为当我只有一个函数时,逻辑是有效的,当我有两个函数时,底部的一个就不起作用了。我尝试将它组合成一个函数,但只有top if语句有效。我尝试过使用$(this.next('a.resultdate').show()

我做错了什么?

您最后一次呼叫是
$(“#tempresults”).show()
。id为
#tempresults
的链接有多少

如果您有多个选项,那么可能会有一个
$(this).child(“.resultdate”).show()
将目标指向正确的选项。

您的最后一个调用是
$(“#tempresults”).show()
。id为
#tempresults
的链接有多少


如果您有多个属性,那么可能会有一个
$(this).child(“.resultdate”).show()
将目标指向正确的属性。

您不需要
返回。它在第一个循环后退出

$(文档).ready->
现在=未定义
现在=新日期
$('ul li time')。每个->
dateTime=Date.parse($(this.attr('dateTime'))
startdate=新日期(dateTime)
startdate.setDate startdate.getDate()-14
enddate=新日期(日期时间)
enddate.setDate enddate.getDate()-2
如果现在>开始日期,现在<结束日期
$(this.next('a.datelink').show()
$('ul li time')。每个->
dateTime=Date.parse($(this.attr('dateTime'))
fixturedate=新日期(日期时间)
如果现在>固定日期
$(“#tempresults”).show()

您不需要返回
s。它在第一个循环后退出

$(文档).ready->
现在=未定义
现在=新日期
$('ul li time')。每个->
dateTime=Date.parse($(this.attr('dateTime'))
startdate=新日期(dateTime)
startdate.setDate startdate.getDate()-14
enddate=新日期(日期时间)
enddate.setDate enddate.getDate()-2
如果现在>开始日期,现在<结束日期
$(this.next('a.datelink').show()
$('ul li time')。每个->
dateTime=Date.parse($(this.attr('dateTime'))
fixturedate=新日期(日期时间)
如果现在>固定日期
$(“#tempresults”).show()

这几乎就是我想要的,除非您将第一个
  • 更改为过去的日期,然后显示#tempresults。我想要它,这样只有当它的
  • 中的日期是过去的时候,才会显示#诱惑结果。我尝试过使用$(this).next('a.resultdate').show(),但这不起作用。我必须使用$('ul li time')。each->dateTime=Date.parse($(this).attr('dateTime'))fixturedate=new Date(dateTime)fixturedate.setDate()+2如果现在>fixturedate$(this)。nextAll('a.resultdate')。show()so.nextAll()而不是.next(),这几乎就是我想要的,除非您将第一个
  • 更改为过去的日期,然后显示#tempresults。我想要它,这样只有当它的
  • 中的日期是过去的时候,才会显示#诱惑结果。我尝试过使用$(this).next('a.resultdate').show(),但这不起作用。我必须使用$('ul li time')。each->dateTime=Date.parse($(this).attr('dateTime'))fixturedate=new Date(dateTime)fixturedate.setDate()+2如果现在>fixturedate$(this)。nextAll('a.resultdate')。show()so.nextAll()而不是.next()
    $(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
    
    $(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()
    
      $('ul li time').each ->
        dateTime = Date.parse($(this).attr('datetime'))
        fixturedate = new Date(dateTime)
        if now > fixturedate
          $( "#tempresults" ).show()