Layui中layDate设置控制可选时间max不超过当前时间

方法一:

    layui.use('laydate', function(){
        var laydate = layui.laydate;

        //限定可选日期
        var ins22 = laydate.render({
            elem: '#test-limit1'
            ,min: '2010-01-01'
            ,max: maxDate()
            ,theme: 'molv'
        });

    });
    function maxDate() {
        var now = new Date();
        return now.getFullYear() + "-" + (now.getMonth() + 1) + "-" + now.getDate();
    }

 

方法二:

    layui.use('laydate', function(){
        var laydate = layui.laydate;

        //限定可选日期
        laydate.render({
            elem: '#test2'
            ,min: '2010-01-01'
            ,max: getNowFormatDate()
            ,theme: 'molv'
        });

    });
    function getNowFormatDate() {
        var date = new Date();
        var seperator1 = "-";
        var seperator2 = ":";
        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 = date.getFullYear() + seperator1 + month + seperator1 + strDate
            + " " + date.getHours() + seperator2 + date.getMinutes()
            + seperator2 + date.getSeconds();
        return currentdate;
    }

 

当前为2020年3月19日,效果图:

Layui中layDate设置控制可选时间max不超过当前时间_第1张图片

 

 

你可能感兴趣的:(前端)