在列中的日期之后隐藏表格行 [英] Hide table row after date in column

查看:168
本文介绍了在列中的日期之后隐藏表格行的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想摆脱Wordpress并通过Amazon S3和Cloudfront发布一个不错的静态网页.我现在拥有网站的唯一动态"部分(使用wordpress)是巡演日期"列表.过去的事件不会显示.

I want to get rid of Wordpress and publish a nice static webpage through amazon S3 and Cloudfront. The only 'dynamic' part of the website I have now (using wordpress) is a list of Tour Dates. Past events are not shown.

我喜欢此功能,但我认为必须有一种使用html和jQuery的方法.不幸的是,我对后者一无所知,因此我真的希望这里有人帮助我找到解决方案.

I like this feature, but I think there must be a way to do this using html and jQuery. Unfortunately I know nothing about the latter so I was really hoping for someone here to help me find the solution.

如果td中的日期早于今天的日期,如何隐藏表格行?<<我无法上班的那个,尤其是因为其中包含了许多我不需要的其他功能.

How to hide a table row if date in td is older than today's date? << That one I could not get to work, especially because there are a lot of other functions included I do not need.

我需要的是一个表,有一些行,每一行都有一个包含日期的单元格(欧洲日期格式DD-MM-YY).日期一过,我便希望隐藏该行.

What I need is a table, with some rows, each row has one cell containing a date (In european date format DD-MM-YY). As soon as the date is in the past, I would like the row to be hidden.

<table>
<tr>
 <th>Date</th>
 <th>Other stuff</th>  
 <th>Some more stuff</th>
</tr>

<tr>
 <td>15-05-2015</td>
 <td>Bla Bla Bla</td>
 <td>Some more bla</td>    
</tr>

<tr>
 <td>11-07-2035</td>
 <td>Bla Bla Bla 2</td>
 <td>Some more bla 2</td>    
</tr>
</table>

因此,在这种情况下,包含内容的第一行将被隐藏,因为它已经过去,而第二行则将在不久的将来可见.希望有一些简单的解决方案!

So in this case the first row with content would be hidden since it is in the past and the second one would be visible since its in the far future. Hopefully there is some easy solution for this!

推荐答案

这并不困难,但是很长的路要走, 我正在尝试为您解释其中的一部分,

its not difficult but it a long way, im trying to explain a part of that for you,

第一行是标题,所以我们不想操纵它, 在可能需要隐藏的行中添加一个类,如.datacheck

the first row is heading so we do not want to manipulate that, add a class to the rows that may be need to be hide like .datacheck

,然后我们尝试制作一些很酷的东西,例如jquery 我们将接着检查每一行,并获取日期列,并将其转换为可比较的日期格式,然后决定显示还是隐藏,

and then we are trying to so some cool stuff whit jquery we are going to check each row one after on and get the date column and convert that to comparable date format and then decide to show or hide,

这是我的主意

$('table tr.datacheck').each(function(){

    var now = new Date().getTime();
    var text_time = $(this).find('td').first().text();
    var time = text_time.split('-'); // separate day,month,year
    var day   = time[0];
    var month = time[1];
    var year  = time[2];

    var row_date = new Date();
    row_date.setFullYear(year, month, day);

    // now we have both time, now time and row time , we can compare

   if (now > row_date.getTime() ) { // if the row date is less that now date
       $(this).hide(); // hide the row here
   }

});

为了便于理解,我以不整洁的方式编写了此代码. 希望对您有帮助

i wrote this code in untidy mode for easy to understanding. hope it helps

这是一个简短的代码

$('table tr.datacheck').each(function(){

    var now  = new Date().getTime();
    var text = $(this).find('td:first').text().split('-');

    var row_date = new Date();
    row_date.setFullYear(time[0], time[1], time[2]);

    // now we have both time, now time and row time , we can compare

   if (now > row_date.getTime() ) { // if the row date is less that now date
       $(this).hide(); // hide the row here
   }

});

这篇关于在列中的日期之后隐藏表格行的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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