根据日期筛选

<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <title>日期筛选demo</title>
</head>

<body>
    起始查询时间:
    <input type="text" id="start-time">
     结束查询时间:
    <input type="text" id="end-time">
    <button id="share-time-btn">查询</button>
    <table>
        <thead>
            <tr>
                <th>时间</th>
                <th>性别</th>
                <th>暂住地</th>
            </tr>
        </thead>
        <tbody>
            <tr>
                <td>2015-10-01</td>
                <td>男</td>
                <td>浙江宁波</td>
            </tr>
            <tr>
                <td>2016-06-06</td>
                <td>女</td>
                <td>浙江杭州</td>
            </tr>
            <tr>
                <td>2016-06-09</td>
                <td>男</td>
                <td>湖南长沙</td>
            </tr>
        </tbody>
    </table>
</body>
<script src="jquery-1.11.1.js"></script>
<script>
$("#share-time-btn").on("click", function() {
    ckdate()
})

function ckdate() {
    var endtime = $('#end-time').val();
    var starttime = $('#start-time').val();
    var start = new Date(starttime.replace("-", "/").replace("-", "/"));
    var end = new Date(endtime.replace("-", "/").replace("-", "/"));
    if (end < start) {
        alert('结束日期不能小于开始日期!');
        $('#end-time').focus();
        return false;
    } else {
        var listData = $("table tbody tr"),
            i = 0;
        listData.hide();
        for (; i < listData.length; i++) {
            var listTime = listData.eq(i).find("td:first").text();
            listTime = new Date(listTime.replace("-", "/").replace("-", "/"));
            if (listTime >= start && listTime <= end) {
                listData.eq(i).show()
            }
        }

    }
}
</script>

</html>

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值