js-选取日期间不能超出当前日期

//获取当前时间,格式YYYY-MM-DD
    function getNowFormatDate() {
        var date = new Date();
        var seperator1 = "-";
        var year = date.getFullYear();
        var month = date.getMonth() + 1;
        var strDate = date.getDate();
        if (month >= 1 && month <= 9) {
            month = "0" + month;
        }
        if (strDate >= 0 && strDate <= 9) {
            strDate = "0" + strDate;
        }
        var currentdate = year + seperator1 + month + seperator1 + strDate;
        return currentdate;
    }


function CompareDate(d1,d2)
{
    return ((new Date(d1.replace(/-/g,"\/"))) > (new Date(d2.replace(/-/g,"\/"))));
}

 var now= getNowFormatDate();
var sj = $('#sj').val();
var flag=CompareDate(sj,now);
if(flag){
    layer.alert('请选择正确的日期');
}else{
//重新获取echarts数据

}

猜你喜欢

转载自blog.csdn.net/carrybest/article/details/80166813