首页 > 解决方案 > jQuery选择日期时间属性大于04-01-2020的时间元素

问题描述

我的页面有几个 <time datetime='...'> ... </time> 元素。我想使用 jQuery 来选择那些具有 datetime 属性授予者的元素,然后是今天。我不高兴地使用了以下脚本。谢谢你的帮助。

$('time[new Date(datetime) > new Date.now()]').click(function(e){...})

标签: javascriptjquery

解决方案


您可以使用filter()来实现,例如:

  $("time").filter(function() {
    return Date.parse($(this).attr("datetime")) > new Date();
  })

推荐阅读