如果td中的日期比今天的日期早,如何隐藏表格行? [英] How to hide a table row if date in td is older than today's date?
本文介绍了如果td中的日期比今天的日期早,如何隐藏表格行?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
是否有解决此问题的js解决方案?
编辑:按要求提供的代码:
< HTML>
< head>
< title>测试< /标题>
< link rel =stylesheethref =https://maxcdn.bootstrapcdn.com/bootstrap/3.2.0/css/bootstrap.min.css>
< link rel =stylesheettype =text / csshref =// cdn.datatables.net/1.10.2/css/jquery.dataTables.css\">
< script type =text / javascriptcharset =utf8src =http://ajax.aspnetcdn.com/ajax/jQuery/jquery-1.8.2.min.js>< /脚本>
< script type =text / javascriptcharset =utf8src =http://ajax.aspnetcdn.com/ajax/jquery.dataTables/1.9.4/jquery.dataTables.min.js >< /脚本>
< script>
// UK日期排序
jQuery.fn.dataTableExt.oSort ['uk_date-asc'] = function(a,b){
var ukDatea = a.split '/');
var ukDateb = b.split('/');
var x =(ukDatea [2] + ukDatea [1] + ukDatea [0])* 1;
var y =(ukDateb [2] + ukDateb [1] + ukDateb [0])* 1; ((x< y)?-1:((x> y)?1:0));
return
};
jQuery.fn.dataTableExt.oSort ['uk_date-desc'] = function(a,b){
var ukDatea = a.split('/');
var ukDateb = b.split('/');
var x =(ukDatea [2] + ukDatea [1] + ukDatea [0])* 1;
var y =(ukDateb [2] + ukDateb [1] + ukDateb [0])* 1; ((x< y)?1:((x> y)?-1:0));
return
};
$ b $(document).ready(function(){
$(#table_id)。dataTable({
aoColumnDefs: [
{aTargets:[2],sType:uk_date}
]
});
});
< / script>
< / head>
< body>
< div class =page-header>
< h2>标题< / h2>
< / div>
< div class =table-responsive>
< table id =table_idclass =table table-striped table-hovercellspacing =0width =100%>
< thead>
< tr>
< th>讲座名称< / th>
讲师< / th>
< th class =uk-date-column>日期< / th>
< th>时间< / th>
< th>链接< / th>
< / tr>
< / thead>
< tbody>
< TR>
< TD>讲座1< / TD>
< TD>讲师1< / TD>
< TD> 01/10/2014< / TD>
< TD ALIGN =RIGHT> 11:00< / TD>
< TD>连结1< / TD>
< / TR>
< TR>
< TD>第2讲< / TD>
< TD>讲师2< / TD>
< TD> 02/10/2014< / TD>
< TD ALIGN =RIGHT> 11:00< / TD>
< TD>连结2< / TD>
< / TR>
< / tbody>
< / table>
< / div>
< / body>
< / html>
解决方案
$(文件).ready(函数(){
$(#table_id)。dataTable({aoColumnDefs:[
{aTargets:[2],sType: uk_date}]});
$('TD.date')。each(function(index){
var q = new Date();
var m = q.getMonth();
var d = q.getDay();
var y = q.getYear();
var date = new Date(y,m ,d);
if(new Date($(this).text())< date){
$(this).parent()。attr(style, display:none)
}
});
});
并向包含日期的列添加日期类。
As a Dr. Frankenstein of coding, I have managed to cobble together a table as exampled [here][1], utilising datatables and UK Date Sorting. The final piece of this puzzle is to find a way to be able to hide an entire row if the date in the corresponding row is older than the current date (i.e. if a date in a td element is older than today's date, hide the row containing that td element).
Is there a js solution to this problem? Any help much appreciated.
Edit: Code as requested:
<html>
<head>
<title>Test</title>
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.2.0/css/bootstrap.min.css">
<link rel="stylesheet" type="text/css" href="//cdn.datatables.net/1.10.2/css/jquery.dataTables.css">
<script type="text/javascript" charset="utf8" src="http://ajax.aspnetcdn.com/ajax/jQuery/jquery-1.8.2.min.js"></script>
<script type="text/javascript" charset="utf8" src="http://ajax.aspnetcdn.com/ajax/jquery.dataTables/1.9.4/jquery.dataTables.min.js"></script>
<script>
// UK Date Sorting
jQuery.fn.dataTableExt.oSort['uk_date-asc'] = function(a, b) {
var ukDatea = a.split('/');
var ukDateb = b.split('/');
var x = (ukDatea[2] + ukDatea[1] + ukDatea[0]) * 1;
var y = (ukDateb[2] + ukDateb[1] + ukDateb[0]) * 1;
return ((x < y) ? -1 : ((x > y) ? 1 : 0));
};
jQuery.fn.dataTableExt.oSort['uk_date-desc'] = function(a, b) {
var ukDatea = a.split('/');
var ukDateb = b.split('/');
var x = (ukDatea[2] + ukDatea[1] + ukDatea[0]) * 1;
var y = (ukDateb[2] + ukDateb[1] + ukDateb[0]) * 1;
return ((x < y) ? 1 : ((x > y) ? -1 : 0));
};
$(document).ready(function() {
$("#table_id").dataTable({
"aoColumnDefs" : [
{"aTargets" : [2] , "sType" : "uk_date"}
]
});
});
</script>
</head>
<body>
<div class="page-header">
<h2>Heading</h2>
</div>
<div class="table-responsive">
<table id="table_id" class="table table-striped table-hover" cellspacing="0" width="100%">
<thead>
<tr>
<th>Lecture name</th>
<th>Lecturer</th>
<th class="uk-date-column">date</th>
<th>time</th>
<th>link</th>
</tr>
</thead>
<tbody>
<TR>
<TD>Lecture 1</TD>
<TD>Lecturer 1</TD>
<TD>01/10/2014</TD>
<TD ALIGN="RIGHT">11:00</TD>
<TD>Link 1</TD>
</TR>
<TR>
<TD>Lecture 2</TD>
<TD>Lecturer 2</TD>
<TD>02/10/2014</TD>
<TD ALIGN="RIGHT">11:00</TD>
<TD>Link 2</TD>
</TR>
</tbody>
</table>
</div>
</body>
</html>
解决方案
$(document).ready(function() {
$("#table_id").dataTable({"aoColumnDefs" : [
{"aTargets" : [2] , "sType" : "uk_date"}]});
$('TD.date').each(function( index ) {
var q = new Date();
var m = q.getMonth();
var d = q.getDay();
var y = q.getYear();
var date = new Date(y,m,d);
if(new Date($(this).text()) < date) {
$(this).parent().attr("style", "display: none")
}
});
});
and add a date class to the column that contains the date.
这篇关于如果td中的日期比今天的日期早,如何隐藏表格行?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文