我有一个表格,中间的日期列已经在Moment.js中解析/格式化。基于时间比较隐藏/显示表格行
我也有两个按钮,点击时,我想要一个按钮只显示日期为<的表格行,24小时后,另一个按钮用于显示日期> 24小时以外日期的表格行。
<script src="https://cdnjs.cloudflare.com/ajax/libs/moment.js/2.15.1/moment.min.js"></script>
<button type="button" id="button1">Less than 24 hours</button>
<button type="button" id="button2">More than 24 hours</button>
<table id="myTable">
<thead>
<tr>
<th colspan="3">Table</th>
</tr>
</thead>
<tbody>
<tr>
<td>A</td>
<td class="dates">12/24/2016 12:45 pm</td>
<td>C</td>
</tr>
<tr style="display:none;">
<td colspan="3"></td>
</tr>
<tr>
<td>A</td>
<td class="dates">11/23/2016 12:45 pm</td>
<td>C</td>
</tr>
<tr style="display:none;">
<td colspan="3"></td>
</tr>
<tr>
<td>A</td>
<td class="dates">12/24/2016 12:45 pm</td>
<td>C</td>
</tr>
<tr style="display:none;">
<td colspan="3"></td>
</tr>
</tbody>
我想我必须使用jquery,这就是我的想法。
$(document).ready(function() {
var m = moment();
var n = m.add(24, 'hours');
var $dates = $('.dates');
$('#button1').click(function() {
if ($dates.each > n) {
$dates.hide();
});
});
});
非常感谢你,这与我正在写的东西类似 –