如何在日期范围内删除元素 [英] How to remove a element during a range of dates

查看:84
本文介绍了如何在日期范围内删除元素的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在查找有关此问题的以前的帖子时遇到麻烦.

I am having trouble locating any previous posts regarding this question.

我的网站上加载了一个div,我想根据日期/月份将其删除

I have a div loaded on my site and i'd like to remove it based on day/month

因此,我想在每年9月7日至1月4日之间的任何日期删除div#example.因此,我不想将其限制为年份,因为这将是每年一次.

So , i'd like to remove div#example on any dates NOT between September 7th and January 4th of each year. So i don't want to limit it to the year , as this will be a yearly occurrence.

这是正确的吗?

  if (/Sept 7|Oct|Nov|Dec|Jan 4/.test(new Date())) {
  } else {
    $("#example").remove();
  }

推荐答案

尝试使用RegExp /-09-0[7-9]|-09-[1-3]|-10-|-11-|-12-|-01-0[1-4]-/.test()new Date().toJSON()作为参数,如果new Date().toJSON()的结果返回true,则调用#example元素

Try utilizing RegExp /-09-0[7-9]|-09-[1-3]|-10-|-11-|-12-|-01-0[1-4]-/ , .test() with new Date().toJSON() as argument, if result of new Date().toJSON() returns true , call .remove() on #example element

if (/-09-0[7-9]|-09-[1-3]|-10-|-11-|-12-|-01-0[1-4]-/.test(new Date().toJSON())) {
  $("#example").remove()
}

这篇关于如何在日期范围内删除元素的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆