我知道使用html和javaScript/jQuery可以做到这一点,但是我对javaScript的了解很少,所以我真的希望有人在这里帮助我解决问题。如果td中的日期早于(大于)今天的日期,则隐藏Boostrap表格行?
如果行(td)中的日期早于当前日期,我该如何隐藏表格中的某一行?
在搜索以前的问题时,我发现了两个类似的问题/答案,但我无法让他们为我工作。
Hide table row after date in column
How to hide a table row if date in td is older than today's date?
什么我是填充了从以.json文件内容的Wenzhixin举表。表的每一行都有一个包含日期的单元格。目前当表加载其内容时,使用下面的脚本按日期排序。我希望实现的附加功能是一旦日期过去,我希望该行被隐藏。
谢谢!
这里是一个的jsfiddle http://jsfiddle.net/ry9f3q1x/ (不知道为什么我的基本排序是没有的jsfiddle工作它工作正常,我常)
我的代码:
HTML
<table data-toggle="table" data-url="/data1.json" data-sort-name="date" data-sort-order="asc">
<thead>
<tr>
<th data-field="eventdate" data-align="center" data-sorter="datesort">Date</th>
<th data-field="thing" data-align="center">thing</th>
<th data-field="thing2" data-align="center">thing2</th>
</tr>
</thead>
</table>
DateSort脚本
function datesort(a,b) {
var x = new Date(a),
y = new Date(b);
if(!isFinite(x-y))
return !isFinite(x) ? 1: -1;
else
return ((x < y) ? -1 : ((x > y) ? 1 : 0));
};
JSON
[
{
"eventdate": '01/14/2017',
"thing": "Hello this is a",
"thing2": "blah blah blah"
},
{
"eventdate": "12/04/2016",
"thing": "Hello this is b",
"thing2": "blah blah blah"
},
{
"eventdate": "05/04/1958",
"thing": "Hello this is c",
"thing2": "blah blah blah"
},
{
"eventdate": "11/23/1960",
"thing": "Hello this is d",
"thing2": "blah blah blah"
},
{
"eventdate": "01/17/2018",
"thing": "Hello this is e",
"thing2": "blah blah blah"
},
{
"eventdate": "01/08/2020",
"thing": "Hello this is f",
"thing2": "blah blah blah"
}
]
那么,这会产生什么样的HTML?你能否提供“* [mcve] *”代码来让我们重现你的问题? –
@DavidThomas提供了一个jsfiddle和更多的代码。 – Sam