根据日期动态删除列表项的代码 [英] Code to Dynamically Remove List items depending on date
问题描述
我正在寻找代码(HTMl,CSS或javascript)或任何解决我问题的方法.最近,我受命为公司网站的设计和功能提供帮助.这里有一个页面,其中列出了雇员在这一年中将要参加的活动.例如:
I am looking for code (HTMl, CSS, or javascript) or any way to solve my issue. I recently have been tasked to help with the design and function of my company's website. There is a page that will have a list of events that an employye will be at during the year. For example:
<div class="container3">
<div class="accordion">
<dl>
<dt>
<a href="#accordion1" aria-expanded="false" aria-controls="accordion1" class="accordion-title accordionTitle js-accordionTrigger">Travel Territory</a>
</dt>
<dd class="accordion-content accordionItem is-collapsed" id="accordion1" aria-hidden="true">
<p><li>Test 1</li>
<li>Test 2</li></p>
</dd>
<dt>
<a href="#accordion2" aria-expanded="false" aria-controls="accordion2" class="accordion-title accordionTitle js-accordionTrigger">Catch me at these schools!</a>
</dt>
<dd class="accordion-content accordionItem is-collapsed" id="accordion2" aria-hidden="true">
<p><ul id="myList">
<li>03/24/2018 at Upper Darby High School 1</li>
<li>03/24/2019 at Upper Darby High School 2</li>
</ul>
</p>
</dd>
</dl>
</div>
</div>
是否有任何代码可以在通过该列表后删除该列表中的元素?还是我必须每天手动将其从列表中删除?
Is there any code that can remove elements of that list after they have passed? OR do I have to go in a manually remove it from the list every day?
我不反对重新创建整个列表的想法,因此任何事情都会有所帮助! 谢谢您提前提供的所有帮助!
I am not against recreating the whole list idea so anything will help! Thank you for all the help in advance!
推荐答案
var filterFunc = function (parentElm, yearToCheck) {
var listElms = $(parentElm).children();
var count = listElms.length;
for (var i=0 ; i < count; i++ ){
var data = $(listElms[i]).html();
var dateText = data.split(" ")[0];
var year = new Date(dateText).getFullYear();
if(year != yearToCheck) {
$(listElms[i]).remove();
}
}
}
filterFunc(parentElement, "2018");
这篇关于根据日期动态删除列表项的代码的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!