且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

在列中的日期之后隐藏表格行

更新时间:2023-12-01 10:57:10

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

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
   }

});